zoukankan      html  css  js  c++  java
  • iOS中创建自定义的圆角按钮

    iOS中很多时候都需要用到指定风格的圆角按钮,尽管UIButton提供了一个方式创建圆角按钮:

    + (id)buttonWithType:(UIButtonType)buttonType;//指定buttonType为UIButtonTypeRoundedRect

    但是这样创建出来的按钮仅仅能支持默认的白底蓝字的风格,不可再进行更改。比如更改了backgroundColor,背景颜色区域仍然覆盖了整个矩形区域。

     

    怎么做呢,通过摸索,以下方法能达到要求:

    复制代码
    UIButton *btn = [[UIButton alloc]initWithFrame:btnFrame];

    // 设置圆角半径
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius = 4;

    //还可设置边框宽度和颜色
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = [UIColor darkGrayColor].CGColor;
    复制代码

     

    这样得到的btn就可按自己需要的风格进行定义了,设置backgroundColor或backgroundImage都只是填充其圆角区域。

  • 相关阅读:
    day06
    样式表
    框架&样式表
    表单
    用表格制作百度首页
    汉企教育实训第第二天
    汉企教育实训第一天感想
    BootStrap前端框架
    MySQL存储过程、存储函数介绍
    日常记录
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3713438.html
Copyright © 2011-2022 走看看