UI常用控件

UI常用控件

//

// ?ViewController.m

// ?UI常用控件

//

// ?Created by lanou on 16/7/10.

// ?Copyright?2016年lanou. All rights reserved.

//

#import"ViewController.h"

@interfaceViewController()

//標(biāo)題標(biāo)簽

@property(nonatomic,strong)UILabel*titleLable;

//左邊按鈕

@property(nonatomic,strong)UIButton*leftBtn;

//右邊按鈕

@property(nonatomic,strong)UIButton*rightBtn;

//顯示圖片

@property(nonatomic,strong)UIImageView*myImageView;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

//定義標(biāo)簽位置與名稱 ?創(chuàng)建并初始化標(biāo)簽

self.titleLable= [[UILabelalloc]initWithFrame:CGRectMake(150,50,150,30)];

注:frame表示控件的坐標(biāo)以及寬高

//設(shè)置標(biāo)簽文本

self.titleLable.text=@"biaoqingdi";

[self.viewaddSubview:self.titleLable];

//定義做按鈕的位置

self.leftBtn= [[UIButtonalloc]initWithFrame:CGRectMake(20,150,45,45)];

//定義按鈕的圖片 ?根據(jù)名字加載圖片

UIImage *leftImage = [UIImageimageNamed:@"left_normal"];

//設(shè)置左按鈕的背景圖片

[self.leftBtnsetBackgroundImage:leftImageforState:(UIControlStateNormal)];

//添加到視圖上面

[self.viewaddSubview:self.leftBtn]; ? ?

//顯示相框名稱 ?設(shè)置imageview顯示的圖片

self.myImageView= [[UIImageView alloc]initWithFrame:CGRectMake(85,100,200,200)];

UIImage *image = [UIImageimageNamed:@"biaoqingdi"];

self.myImageView.image= image;

//顯示相框圖片

[self.viewaddSubview:self.myImageView];

//設(shè)置右按鈕的位置

self.rightBtn=[[UIButtonalloc]initWithFrame:CGRectMake(305,150,45,45)];

//設(shè)置右按鈕的圖片

UIImage *rightImage = [UIImageimageNamed:@"right_normal"];

//設(shè)置右按鈕的背景圖片

[self.rightBtnsetBackgroundImage:rightImageforState:(UIControlStateNormal)];

[self.viewaddSubview:self.rightBtn];


}

-(void)btnClickLister

{

NSLog(@"click btn");

}

-(void)demo {

// ???UIView *view =[u]

//按鈕UIButton

// ???UIButton *button =[UIButton buttonWithType:UIButtonTypeInfoDark];

UIButton*button = [[UIButtonalloc]initWithFrame:CGRectMake(20,50,80,80)];

// ???frame表明了控件的坐標(biāo)和寬高(CGRect類型)

// ???[button setTitle:@"柚子" forState:UIControlStateNormal];

UIImage *image = [UIImageimageNamed:@"left_normal"];

//根據(jù)名字加載圖片

[buttonsetBackgroundImage:imageforState:UIControlStateNormal];

//給按鈕設(shè)置背景圖片

// ??button.backgroundColor = [UIColor redColor];

//按鈕的監(jiān)聽

[buttonaddTarget:selfaction:@selector(btnClickLister)forControlEvents:UIControlEventTouchUpInside];

//添加到視圖上面

[self.viewaddSubview:button];

//相框UIImageView

UIImageView*imageview = [[UIImageViewalloc]initWithFrame:CGRectMake(150,50,200,200)];

UIImage*image1 = [UIImageimageNamed:@"biaoqingdi"];

//設(shè)置imageView顯示的圖片

imageview.image= image1;

[self.viewaddSubview:imageview];

//標(biāo)簽UILabel

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(150,270,150,30)];

//設(shè)置標(biāo)簽文本

label.text=@"濤哥哥";

//設(shè)置居中方式

label.textAlignment=NSTextAlignmentCenter;

label.textColor= [UIColorredColor];

[self.viewaddSubview:label];}

@end




//

// ?ViewController.m

// ?UI常用控件

//

// ?Created by lanou on 16/7/10.

// ?Copyright?2016年lanou. All rights reserved.

//

#import"ViewController.h"

@interfaceViewController ()

//標(biāo)題標(biāo)簽

@property(nonatomic,strong)UILabel*titleLabel;

//左邊按鈕


@property(nonatomic,strong)UIButton*leftBtn;

//右邊按鈕

@property(nonatomic,strong)UIButton*rightBtn;

//顯示圖片

@property(nonatomic,strong)UIImageView*myImageView;

//定義數(shù)組名

@property(nonatomic,strong)NSArray*imageNames;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

self.imageNames=@[@"biaoqingdi",@"bingli",@"chiniupa",@"danteng",@"wangba"];

//定義標(biāo)簽位置與名稱

self.titleLabel= [[UILabelalloc]initWithFrame:CGRectMake(150,50,150,30)];

// 設(shè)置標(biāo)簽文本

self.titleLabel.text=@"biaoqingdi";

[self.viewaddSubview:self.titleLabel];

//定義做按鈕的位置

self.leftBtn= [[UIButtonalloc]initWithFrame:CGRectMake(20,150,45,45)];

//關(guān)閉交互 ?BOOL類型

self.leftBtn.userInteractionEnabled=NO;

//定義按鈕的圖片

UIImage*leftImage = [UIImageimageNamed:@"left_disable"];

//設(shè)置左按鈕的背景圖片

[self.leftBtnsetBackgroundImage:leftImage forState:(UIControlStateNormal)];

[self.viewaddSubview:self.leftBtn];

//顯示相框名稱

self.myImageView= [[UIImageView alloc]initWithFrame:CGRectMake(85,100,200,200)];

UIImage *image = [UIImageimageNamed:@"biaoqingdi"];

self.myImageView.image= image;

//顯示相框圖片

[self.viewaddSubview:self.myImageView];

//設(shè)置右按鈕的位置

self.rightBtn=[[UIButtonalloc]initWithFrame:CGRectMake(305,150,45,45)];

//設(shè)置右按鈕的圖片 ? 根據(jù)名字加載圖片

UIImage *rightImage = [UIImageimageNamed:@"right_normal"];

//設(shè)置右按鈕的背景圖片

[self.rightBtnsetBackgroundImage:rightImageforState:(UIControlStateNormal)];

[self.viewaddSubview:self.rightBtn];

//按鈕的監(jiān)聽

[self.rightBtnaddTarget:selfaction:@selector(rightBtnAction)forControlEvents:(UIControlEventTouchUpInside)];

[self.leftBtnaddTarget:selfaction:@selector(leftBtnAction)forControlEvents:(UIControlEventTouchUpInside)];

}

-(void)rightBtnAction

{

//切換到下一張圖片

//獲取當(dāng)前是第幾張圖片

NSIntegerindex = [self.imageNamesindexOfObject:self.titleLabel.text];

//不是為最后一張才切換到下一張

if(index <4){

if(index ==3){

//改變右邊按鈕的圖片和關(guān)閉交互

self.rightBtn.userInteractionEnabled=NO;

UIImage*image = [UIImageimageNamed:@"right_disable"];

[self.rightBtnsetBackgroundImage:image forState:(UIControlStateNormal)];

}else{

//左邊按鈕和右邊按鈕都是在一個(gè)正常狀態(tài)

self.leftBtn.userInteractionEnabled=YES;

self.rightBtn.userInteractionEnabled=YES;

UIImage*leftNormal = [UIImageimageNamed:@"left_normal"];

UIImage*rightNormal =[UIImageimageNamed:@"right_normal"];

[self.leftBtnsetBackgroundImage:leftNormal forState:(UIControlStateNormal)];

[self.rightBtnsetBackgroundImage:rightNormal forState:(UIControlStateNormal)];

}

NSString*nextTitle =self.imageNames[index+1];

self.titleLabel.text= nextTitle;

self.myImageView.image= [UIImageimageNamed:nextTitle];

}

}

-(void)leftBtnAction

{

NSIntegerindex = [self.imageNamesindexOfObject:self.titleLabel.text];

if(index >0){

if(index ==1){

//改變左邊按鈕的圖片和關(guān)閉交互

self.leftBtn.userInteractionEnabled=NO;

UIImage*image = [UIImageimageNamed:@"left_disable"];

[self.leftBtnsetBackgroundImage:image forState:(UIControlStateNormal)];

}else{

//左邊按鈕和右邊按鈕都是在一個(gè)正常狀態(tài)

self.leftBtn.userInteractionEnabled=YES;

self.rightBtn.userInteractionEnabled=YES;

UIImage*leftNormal = [UIImageimageNamed:@"left_normal"];

UIImage*rightNormal =[UIImageimageNamed:@"right_normal"];

[self.leftBtnsetBackgroundImage:leftNormal forState:(UIControlStateNormal)];

[self.rightBtnsetBackgroundImage:rightNormal forState:(UIControlStateNormal)];

}

NSString*preTitle =self.imageNames[index-1];

self.titleLabel.text= preTitle;

self.myImageView.image = [UIImage imageNamed:preTitle];

}

}

-(void)btnClickLister

{

NSLog(@"click btn");

}

-(void)demo {

// ???UIView *view =[u]

//按鈕UIButton

// ???UIButton *button =[UIButton buttonWithType:UIButtonTypeInfoDark];

UIButton*button = [[UIButtonalloc]initWithFrame:CGRectMake(20,50,80,80)];

// ???frame表明了控件的坐標(biāo)和寬高(CGRect類型)

// ???[button setTitle:@"阿陶" forState:UIControlStateNormal];

UIImage*image = [UIImageimageNamed:@"left_normal"];

//根據(jù)名字加載圖片

[buttonsetBackgroundImage:image forState:UIControlStateNormal];

//給按鈕設(shè)置背景圖片

// ??button.backgroundColor = [UIColor redColor];

//按鈕的監(jiān)聽

[buttonaddTarget:selfaction:@selector(btnClickLister) forControlEvents:UIControlEventTouchUpInside];

//添加到視圖上面

[self.viewaddSubview:button];

//相框UIImageView

UIImageView*imageview = [[UIImageViewalloc]initWithFrame:CGRectMake(150,50,200,200)];

UIImage*image1 = [UIImageimageNamed:@"biaoqingdi"];

//設(shè)置imageView顯示的圖片

imageview.image= image1;

[self.viewaddSubview:imageview];

//標(biāo)簽UILabel

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(150,270,150,30)];

//設(shè)置標(biāo)簽文本

label.text=@"濤哥哥";

//設(shè)置居中方式

label.textAlignment=NSTextAlignmentCenter;

label.textColor= [UIColorredColor];

[self.view addSubview:label];}

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末狡刘,一起剝皮案震驚了整個(gè)濱河市母剥,隨后出現(xiàn)的幾起案子寻拂,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,248評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡主卫,警方通過查閱死者的電腦和手機(jī)逃默,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,681評(píng)論 2 381
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來队秩,“玉大人笑旺,你說我怎么就攤上這事♀勺剩” “怎么了筒主?”我有些...
    開封第一講書人閱讀 153,443評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵锤躁,是天一觀的道長(zhǎng)它匕。 經(jīng)常有香客問我辑甜,道長(zhǎng)钾怔,這世上最難降的妖魔是什么寸癌? 我笑而不...
    開封第一講書人閱讀 55,475評(píng)論 1 279
  • 正文 為了忘掉前任掺冠,我火速辦了婚禮狮腿,結(jié)果婚禮上杨名,老公的妹妹穿的比我還像新娘熊经。我一直安慰自己泽艘,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,458評(píng)論 5 374
  • 文/花漫 我一把揭開白布镐依。 她就那樣靜靜地躺著匹涮,像睡著了一般。 火紅的嫁衣襯著肌膚如雪槐壳。 梳的紋絲不亂的頭發(fā)上然低,一...
    開封第一講書人閱讀 49,185評(píng)論 1 284
  • 那天,我揣著相機(jī)與錄音务唐,去河邊找鬼雳攘。 笑死,一個(gè)胖子當(dāng)著我的面吹牛枫笛,可吹牛的內(nèi)容都是我干的吨灭。 我是一名探鬼主播,決...
    沈念sama閱讀 38,451評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼刑巧,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼沃于!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起海诲,我...
    開封第一講書人閱讀 37,112評(píng)論 0 261
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎檩互,沒想到半個(gè)月后特幔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,609評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡闸昨,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,083評(píng)論 2 325
  • 正文 我和宋清朗相戀三年蚯斯,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了薄风。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,163評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡拍嵌,死狀恐怖遭赂,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情横辆,我是刑警寧澤撇他,帶...
    沈念sama閱讀 33,803評(píng)論 4 323
  • 正文 年R本政府宣布,位于F島的核電站狈蚤,受9級(jí)特大地震影響困肩,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜脆侮,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,357評(píng)論 3 307
  • 文/蒙蒙 一锌畸、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧靖避,春花似錦潭枣、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,357評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至粘咖,卻和暖如春蚣抗,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背瓮下。 一陣腳步聲響...
    開封第一講書人閱讀 31,590評(píng)論 1 261
  • 我被黑心中介騙來泰國打工翰铡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人讽坏。 一個(gè)月前我還...
    沈念sama閱讀 45,636評(píng)論 2 355
  • 正文 我出身青樓锭魔,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國和親路呜。 傳聞我的和親對(duì)象是個(gè)殘疾皇子迷捧,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,925評(píng)論 2 344

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