【问题标题】:Custom UIButton iOS App自定义 UIButton iOS 应用
【发布时间】:2014-01-04 01:50:40
【问题描述】:

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

我想自定义这个按钮,我想要一个这样的按钮:

我的代码是这样的,但我无法制作圆角:

_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];

我该怎么办?

【问题讨论】:

  • 字体类型没问题..

标签: ios uibutton


【解决方案1】:

我会使用上面的图片来设置按钮的图片,而不是绘制形状:

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

【讨论】:

  • 这并不容易,这个按钮在滚动视图中,当用户滚动时它的宽度会发生变化。如果我插入图像,它将被破坏
  • 对于文本颜色,检查 RGB 值是否介于 0.0 和 1.0 之间。我真的不明白您为什么需要手动绘制视图,但请记住,如果这样做,您可能会获得最差的性能。
  • 我通过 Google 快速搜索找到了这个。使用 Quartz2D techotopia.com/index.php/… 绘制椭圆
【解决方案2】:

这是制作圆角 UIView 的方法:IOS: create a UIImage or UIImageView with rounded corners

那么文本颜色呢……一切似乎都很好。也许它不起作用,因为您为同一状态设置了两次标题颜色。而你的代码底部字符串的第二个是多余的。

【讨论】:

  • 我认为cornerRadiusclipsToBounds 无法实现这种椭圆形。
  • 好的,对于文本颜色,你是对的!我没有看到错误。我已经更新了答案,效果很好!谢谢!
猜你喜欢
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-12
  • 1970-01-01
  • 2011-08-10
相关资源
最近更新 更多