UI控件

//

//ViewController.m

//UI常用控件

//

//Created bylanou on 16/7/10.

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

//

#import"ViewController.h"

@interfaceViewController ()

//標題標簽

@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"];

//定義標簽位置與名稱

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

self.titleLabel.text=@"biaoqingdi";

[self.viewaddSubview:self.titleLabel];

//定義做按鈕的位置

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

//關閉交互

self.leftBtn.userInteractionEnabled=NO;

//定義按鈕的圖片

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

//設置左按鈕的背景圖片

[self.leftBtnsetBackgroundImage:leftImage

forState:(UIControlStateNormal)];

[self.viewaddSubview:self.leftBtn];

//顯示相框名稱

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

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

self.myImageView.image= image;

//顯示相框圖片

[self.viewaddSubview:self.myImageView];

//設置右按鈕的位置

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

\

//設置右按鈕的圖片

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

//設置右按鈕的背景圖片

[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

{

//切換到下一張圖片

//獲取當前是第幾張圖片

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

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

if(index <4){

if(index ==3){

//改變右邊按鈕的圖片和關閉交互

self.rightBtn.userInteractionEnabled=NO;

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

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

}else{

//左邊按鈕和右邊按鈕都是在一個正常狀態(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){

//改變左邊按鈕的圖片和關閉交互

self.leftBtn.userInteractionEnabled=NO;

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

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

}else{

//左邊按鈕和右邊按鈕都是在一個正常狀態(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表明了控件的坐標和寬高(CGRect類型)

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

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

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

[buttonsetBackgroundImage:image forState:UIControlStateNormal];

//給按鈕設置背景圖片

//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"];

//設置imageView顯示的圖片

imageview.image= image1;

[self.viewaddSubview:imageview];

//標簽UILabel

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

//設置標簽文本

label.text=@"濤哥哥";

//設置居中方式

label.textAlignment=NSTextAlignmentCenter;

label.textColor= [UIColorredColor];

[self.viewaddSubview:label];}

@end

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市思恐,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌基跑,老刑警劉巖描焰,帶你破解...
    沈念sama閱讀 218,858評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異篱竭,居然都是意外死亡步绸,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評論 3 395
  • 文/潘曉璐 我一進店門坪圾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來惑朦,“玉大人,你說我怎么就攤上這事病梢。” “怎么了蜓陌?”我有些...
    開封第一講書人閱讀 165,282評論 0 356
  • 文/不壞的土叔 我叫張陵钮热,是天一觀的道長。 經常有香客問我飒责,道長仆潮,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,842評論 1 295
  • 正文 為了忘掉前任拾并,我火速辦了婚禮鹏浅,結果婚禮上,老公的妹妹穿的比我還像新娘篡石。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 67,857評論 6 392
  • 文/花漫 我一把揭開白布胖眷。 她就那樣靜靜地躺著霹崎,像睡著了一般。 火紅的嫁衣襯著肌膚如雪境析。 梳的紋絲不亂的頭發(fā)上派诬,一...
    開封第一講書人閱讀 51,679評論 1 305
  • 那天,我揣著相機與錄音沛鸵,去河邊找鬼。 笑死曲掰,一個胖子當著我的面吹牛,可吹牛的內容都是我干的乱豆。 我是一名探鬼主播吊趾,決...
    沈念sama閱讀 40,406評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼续滋!你這毒婦竟也來了孵奶?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,311評論 0 276
  • 序言:老撾萬榮一對情侶失蹤朗恳,失蹤者是張志新(化名)和其女友劉穎载绿,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體崭庸,經...
    沈念sama閱讀 45,767評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡怕享,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年函筋,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片跌帐。...
    茶點故事閱讀 40,090評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡谨敛,死狀恐怖,靈堂內的尸體忽然破棺而出佣盒,到底是詐尸還是另有隱情,我是刑警寧澤盯仪,帶...
    沈念sama閱讀 35,785評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站全景,受9級特大地震影響,放射性物質發(fā)生泄漏滞伟。R本人自食惡果不足惜炕贵,卻給世界環(huán)境...
    茶點故事閱讀 41,420評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望亩钟。 院中可真熱鬧鳖轰,春花似錦、人聲如沸蕴侣。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽忆肾。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間稳强,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評論 1 271
  • 我被黑心中介騙來泰國打工退疫, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留渠缕,地道東北人。 一個月前我還...
    沈念sama閱讀 48,298評論 3 372
  • 正文 我出身青樓褒繁,卻偏偏與公主長得像亦鳞,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,033評論 2 355

推薦閱讀更多精彩內容