UILabel & UITextFiled &UIButton & UIImageView

UILabel 標(biāo)簽

@property(nullable, nonatomic,copy)   NSString           *text;內(nèi)容
@property(null_resettable, nonatomic,strong) UIFont      *font; 字體
@property(null_resettable, nonatomic,strong) UIColor     *textColor; 顏色
@property(nonatomic) NSInteger numberOfLines; 行數(shù)(0為允許任意行)
@property(nonatomic)        NSTextAlignment    textAlignment;對齊方式
UITextFiled 文本輸入框

@property(nullable, nonatomic,copy)   NSString               *text; 內(nèi)容
@property(nullable, nonatomic,strong) UIColor                *textColor;內(nèi)
容顏色
@property(nullable, nonatomic,strong) UIFont                 *font; 字體
@property(nonatomic)        NSTextAlignment         textAlignment; 對齊方式
@property(nullable, nonatomic,copy)   NSString               *placeholder;提示信息
@property(nonatomic)        UITextBorderStyle       borderStyle;邊框樣式
UIButton 按鈕

- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state; 設(shè)置指定狀態(tài)的標(biāo)題
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR;設(shè)置指定狀態(tài)的標(biāo)題顏色
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;設(shè)置指定狀態(tài)顯示的圖片
UIControl 控件

- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;添加監(jiān)聽事件
參數(shù)1:事件觸發(fā)時執(zhí)行對象
參數(shù)2:事件觸發(fā)時執(zhí)行指定對象中的指定方法
參數(shù)3:監(jiān)聽的事件類型
UIImageView 圖片視圖

- (instancetype)initWithImage:(nullable UIImage *)image;根據(jù)圖片創(chuàng)建視圖,視圖的大小跟圖片一樣大
@property (nullable, nonatomic, strong) UIImage *image; 圖片
UIImage 圖片

+ (nullable UIImage *)imageNamed:(NSString *)name;根據(jù)名稱生成圖片
+ (nullable UIImage *)imageWithData:(NSData *)data;根據(jù)二進(jìn)制生成圖片

案例1(加法計算器)

加法計算器
案例2(小飛機(jī))
//定義方向枚舉
typedef NS_ENUM(NSInteger, DirType) {
    DIR_UP = 101,
    DIR_LEFT = 102,
    DIR_DOWN = 103,
    DIR_RIGHT = 104
};
@interface ViewController ()
//小飛機(jī)按鈕
@property (nonatomic,weak) UIButton *planeButton;
@end
//設(shè)置界面
-(void)setUpUI{
    //設(shè)置背景視圖
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
    [self.view addSubview:iv];
    
    //設(shè)置飛機(jī)
    UIButton *planeButton = [[UIButton alloc] init];
    [planeButton setImage:[UIImage imageNamed:@"hero1"] forState:UIControlStateNormal];
    [planeButton setImage:[UIImage imageNamed:@"hero2"] forState:UIControlStateHighlighted];
    [self.view addSubview:planeButton];
    [planeButton sizeToFit];
    planeButton.center = self.view.center;
    planeButton.center = CGPointMake(self.view.center.x, self.view.center.y - 200);
    //記錄變量
    self.planeButton = planeButton;
    
    //設(shè)置方向按鈕
    CGFloat offset = 30;
    //方向按鈕根基 偏移值CGPoint normal圖片 helight圖片 tag生成
    CGPoint center = CGPointMake(self.view.center.x, self.view.center.y + 180);
    [self creatButtonWith:@"top_normal" :@"top_highlighted" :CGPointMake(0, -offset) :DIR_UP :center];
    [self creatButtonWith:@"left_normal" :@"left_highlighted" :CGPointMake(-offset, 0) :DIR_LEFT :center];
    [self creatButtonWith:@"bottom_normal" :@"bottom_highlighted" :CGPointMake(0, offset) :DIR_DOWN :center];
    [self creatButtonWith:@"right_normal" :@"right_highlighted" :CGPointMake(offset, 0) :DIR_RIGHT :center];
    
}
//創(chuàng)建按鈕并添加到視圖
-(void)creatButtonWith:(NSString *)normalName :(NSString *)helightName :(CGPoint)offset :(NSInteger)tag :(CGPoint)center{
    UIButton *btn = [[UIButton alloc] init];
    [self.view addSubview:btn];
    [btn setImage:[UIImage imageNamed:normalName] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:helightName] forState:UIControlStateHighlighted];
    btn.tag = tag;
    btn.frame = CGRectMake(0, 0, 40, 40);
    btn.center = CGPointMake(center.x + offset.x, center.y + offset.y);
    
    [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
}
//點(diǎn)擊按鈕
-(void)clickButton:(UIButton *)sender {
    //獲取初始位置
    CGRect frame = self.planeButton.frame;
    //每次點(diǎn)擊移動的距離
    CGFloat offset = 20;
    //修改位置
    switch (sender.tag) {
        case DIR_UP:
            frame.origin.y -= offset;
            break;
        case DIR_LEFT:
            frame.origin.x -= offset;
            break;
        case DIR_DOWN:
            frame.origin.y += offset;
            break;
        case DIR_RIGHT:
            frame.origin.x += offset;
            break;
            
        default:
            break;
    }
    //賦值
    self.planeButton.frame = frame;
}
@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文是對論文《The Z1: Architecture and Algorithms of Konrad Zuse...
    逸之閱讀 4,833評論 15 12
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評論 19 139
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,734評論 18 399
  • 那在從前,忘了從何時間, 可我卻記得地點(diǎn), 只是一眼, 心里便有了你的容顏! 在那素色流年的某一天, 空靈婉轉(zhuǎn),歌...
    孤帆1314閱讀 406評論 0 0
  • 胡來三年回顧之三 之15年 穿過 穿過父親的山川,冰河,綠洲 置于一個古老荒蕪的人世 低于草,低于羊, 低于藏原苦...
    胡來先生閱讀 555評論 0 2

友情鏈接更多精彩內(nèi)容