2013-12-16 88 views
0

我正在开发一个iOS应用程序,我必须插入一个UIButton。自定义UIButton iOS应用程序

我想自定义此按钮,我想有这样一个按钮:

enter image description here

我的代码是这样的,但我不能做圆角:

_topImagesScrollViewButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
_topImagesScrollViewButton.frame = CGRectMake(screenWidth/2-25, topBarHeight+paddHeight, 37 , 37); 
_topImagesScrollViewButton.backgroundColor = [UIColor colorWithRed:red_middle green:green_middle blue:blue_middle alpha:alpha_middle]; 
[_topImagesScrollViewButton setTitle:@"Top" forState:UIControlStateNormal]; 
[_topImagesScrollViewButton setTitleColor:[UIColor colorWithRed:red_text green:green_text blue:blue_text alpha:alpha_text] forState:UIControlStateNormal];forState:UIControlStateNormal]; 
[_topImagesScrollViewButton addTarget:self action:@selector(topImagesScrollVieButtonTapped) forControlEvents:UIControlEventTouchUpInside]; 

我该怎么办?

+0

字体类型不是问题.. – lubilis

回答

0

这是如何使UIView的圆角:IOS: create a UIImage or UIImageView with rounded corners

和有关文本什么颜色......一切似乎都没问题。也许它不起作用,因为您为相同的状态设置了两次标题颜色。而你的代码的底部字符串的第二个是多余的。

+0

我不认为用“cornerRadius”和“clipsToBounds”可以达到这个椭圆形状。 – amb

+0

好的,对于文本颜色你是对的!我没有看到错误。我已经更新了答案,它效果很好!谢谢! – lubilis

3

我就用上面的图像设置按钮的图像,而不是绘制形状:

[_topImagesScrollViewButton setImage:@"yourimagename.png" forState:UIControlStateNormal]; 
+0

这不是那么容易,这个按钮在滚动视图中,当用户滚动时它的宽度会改变。如果我插入图像,它将被破坏 – lubilis

+0

对于文本颜色检查RGB值介于0.0和1.0之间。我不明白为什么你需要手工绘制视图,但请记住,如果你这样做,你可能会得到最差的表现。 – amb

+0

我用快速的Google搜索找到了这个。使用Quartz2D绘制椭圆http://www.techotopia.com/index.php/An_iOS_4_iPhone_Graphics_Drawing_Tutorial_using_Quartz_2D#Drawing_an_Ellipse_or_Circle – amb