UILabel & UITextFiled &UIButton & UIImageView

UILabel 標簽

@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; 設置指定狀態(tài)的標題
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR;設置指定狀態(tài)的標題顏色
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;設置指定狀態(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ù)二進制生成圖片

案例1(加法計算器)

加法計算器
案例2(小飛機)
//定義方向枚舉
typedef NS_ENUM(NSInteger, DirType) {
    DIR_UP = 101,
    DIR_LEFT = 102,
    DIR_DOWN = 103,
    DIR_RIGHT = 104
};
@interface ViewController ()
//小飛機按鈕
@property (nonatomic,weak) UIButton *planeButton;
@end
//設置界面
-(void)setUpUI{
    //設置背景視圖
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
    [self.view addSubview:iv];
    
    //設置飛機
    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;
    
    //設置方向按鈕
    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];
}
//點擊按鈕
-(void)clickButton:(UIButton *)sender {
    //獲取初始位置
    CGRect frame = self.planeButton.frame;
    //每次點擊移動的距離
    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)系作者
  • 序言:七十年代末墅冷,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子寞忿,更是在濱河造成了極大的恐慌,老刑警劉巖腔彰,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異霹抛,居然都是意外死亡,警方通過查閱死者的電腦和手機杯拐,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來朗兵,“玉大人,你說我怎么就攤上這事余掖〗嘎常” “怎么了?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵仅醇,是天一觀的道長。 經(jīng)常有香客問我着憨,道長,這世上最難降的妖魔是什么漆改? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任准谚,我火速辦了婚禮,結(jié)果婚禮上柱衔,老公的妹妹穿的比我還像新娘。我一直安慰自己唆铐,他們只是感情好,可當我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布顺少。 她就那樣靜靜地躺著,像睡著了一般脆炎。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上秒裕,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天,我揣著相機與錄音几蜻,去河邊找鬼。 笑死入蛆,一個胖子當著我的面吹牛硕勿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播源武,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼粱栖!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起闹究,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎赏寇,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體嗅定,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡用踩,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了碎乃。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡荠锭,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出证九,到底是詐尸還是另有隱情删豺,我是刑警寧澤呀页,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站蓬蝶,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏丸氛。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一缓窜、第九天 我趴在偏房一處隱蔽的房頂上張望谍咆。 院中可真熱鬧,春花似錦摹察、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽克滴。三九已至,卻和暖如春偿曙,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背望忆。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留启摄,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓歉备,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子帽驯,可洞房花燭夜當晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容

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