iOS开发教程之UI-UIButton
程序员文章站
2022-04-15 19:44:20
ios开发教程之ui-uibutton,同样在rootviewcontroller.m文件中。
- (void)viewdidload {
[super viewdidload];...
ios开发教程之ui-uibutton,同样在rootviewcontroller.m文件中。
- (void)viewdidload { [super viewdidload]; //按钮 uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; button.backgroundcolor = [uicolor greencolor]; [self.view addsubview:button]; //按钮指定位置 button.frame = cgrectmake(10, 100, 350, 300); //设置按钮上的文字 [button settitle:@"淘宝" forstate:uicontrolstatenormal]; //设置字体颜色 [button settitlecolor:[uicolor orangecolor] forstate:uicontrolstatenormal]; //背景图片 //创建一张图片 //uiimage *image = [uiimage imagenamed:@"淘宝.jpeg"];//jpg不用写格式 //[button setbackgroundimage:image forstate:uicontrolstatenormal]; //前景图片 [button setimage:[uiimage imagenamed:@"淘宝.jpeg"] forstate:uicontrolstatenormal]; //调整文字和图片的位置 [button setimageedgeinsets:uiedgeinsetsmake(0, 0, 0, 50)]; [button settitleedgeinsets:uiedgeinsetsmake(0, 20, 0, 0)]; //添加点击事件 [button addtarget:self action:@selector(youtouchme)forcontrolevents:uicontroleventtouchupinside]; } //实现按钮的点击方法 -(void)youtouchme { nslog(@"你摸了我"); }
下一篇: C库头文件(C99)