`
lefthand0302
  • 浏览: 9439 次
  • 来自: ...
文章分类
社区版块
存档分类
最新评论

UIButton,设置为UIButtonTypeCustom类型时,做圆角效果

    博客分类:
  • IOS
阅读更多
       我是ios开发新手。

       今天遇到一个问题,想要将UIButton设置背景色,结果发现只有将Type设置为UIButtonTypeCustom时,背景色才起作用。
      但是此时,圆角效果却木有了……。网上搜索了半天,基本上都说通过layer的几个方法设置,但是copy代码后报错“Receivertype 'CALayer'forinstance message is a forward declaration”。
     最后从一个老外的帖子里找到答案:
      Add QuartzCore.framework to your project and this line to your .m file.
      #import <QuartzCore/QuartzCore.h>

我的示例代码如下:
     
  UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        moreButton.frame = CGRectMake(1.0f, 1.0f, cell.contentView.frame.size.width-2, cell.contentView.frame.size.height-2);
        [moreButton.layer setMasksToBounds:YES];
        [moreButton.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
        [moreButton.layer setBorderWidth:1.0]; //边框宽度
        moreButton.backgroundColor = [UIColor clearColor];




原文地址:http://stackoverflow.com/questions/7813379/what-does-receiver-type-calayer-for-instance-message-is-a-forward-declaration
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics