IOS开发实现UIButton效果具体方法
来源:爱站网时间:2022-10-08编辑:网友分享
本篇文章主要分析了IOS开发实现UIButton效果具体方法内容,有需要的小伙伴可以来了解一下。希望爱站技术频道小编整理的知识点对大家学习IOS开发有所帮助。
在使用UIButton的时候,需要实现UIButton左边图片,图片后面紧跟文字效果比较麻烦,简单实现方法具体代码如下:
(void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = RGB(235, 235, 240); UIButton *oneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, kHeaderHeight + 8, kScreenWidth, 40)]; [oneButton setImage:[UIImage imageNamed:@"icon_party_knowledge_rights_obligations"] forState:UIControlStateNormal]; [oneButton setTitle:@"第一个" forState:UIControlStateNormal]; oneButton.titleLabel.font = FONT(12); [oneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [oneButton setImageEdgeInsets:UIEdgeInsetsMake(2, 8, 0, kScreenWidth - 50)]; [oneButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, kScreenWidth - 100)]; oneButton.backgroundColor = [UIColor whiteColor]; [oneButton addTarget:self action:@selector(oneButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:oneButton]; UIButton *twoButton = [[UIButton alloc] initWithFrame:CGRectMake(0, oneButton.maxY + 8, kScreenWidth, 40)]; [twoButton setImage:[UIImage imageNamed:@"icon_party_knowledge_dues_collection_standard"] forState:UIControlStateNormal]; [twoButton setTitle:@"第二个" forState:UIControlStateNormal]; twoButton.titleLabel.font = FONT(12); [twoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [twoButton setImageEdgeInsets:UIEdgeInsetsMake(2, 8, 0, kScreenWidth - 50)]; [twoButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, kScreenWidth - 100)]; twoButton.backgroundColor = [UIColor whiteColor]; [twoButton addTarget:self action:@selector(twoButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:twoButton]; //右箭头 for (int i = 0; i
实现效果:
以上IOS开发实现UIButton效果具体方法的全部内容了,不知道朋友们看完后是不是对此有所了解了。关注爱站技术频道网站,小编每天不定时更新各种类型的技术文章。
下一篇:iOS开发有几种延迟执行方法