您的位置:首页 > 产品设计 > UI/UE

UIButton(左边图片右边文字)

2016-06-16 17:01 549 查看


normal



highlighted

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 100, 100, 50);
button.backgroundColor = [UIColor clearColor];
//设置button正常状态下的图片
[button setImage:[UIImage imageNamed:@"_star_normal.png"] forState:UIControlStateNormal];
//设置button高亮状态下的图片
[button setImage:[UIImage imageNamed:@"_star_highlighted.png"] forState:UIControlStateHighlighted];
//设置button正常状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"_normal.png"] forState:UIControlStateNormal];
//设置button高亮状态下的背景图
[button setBackgroundImage:[UIImage imageNamed:@"_highlighted.png"] forState:UIControlStateHighlighted];
//button图片的偏移量,距上左下右分别(10, 10, 10, 60)像素点
button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 60);
[button setTitle:@"南瓜瓜" forState:UIControlStateNormal];
//button标题的偏移量,这个偏移量是相对于图片的
button.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//设置button正常状态下的标题颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//设置button高亮状态下的标题颜色
[button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont systemFontOfSize:14];
[self.view addSubview:button];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios开发 uibutton