设置圆角


#import <QuartzCore/QuartzCore.h>



     icon.layer.masksToBounds = YES;
        icon.layer.cornerRadius = 5.0;
        icon.layer.borderWidth = 0.5;
        icon.layer.borderColor = [[UIColor grayColor] CGColor];
       

Android 的 `drawable` 中设置圆角可以通过创建一个 XML 形状文件来实现。以下是具体步骤和示例代码: ### 创建 XML 形状文件 在 `res/drawable` 目录下创建一个新的 XML 文件,例如 `rounded_corner.xml`。在这个文件中,可以使用 `<shape>` 标签来定义形状,并使用 `<corners>` 标签来设置圆角。 ```xml <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 设置填充颜色 --> <solid android:color="#FF0000" /> <!-- 设置圆角半径 --> <corners android:radius="10dp" /> </shape> ``` 在上述代码中: - `<solid>` 标签用于设置形状的填充颜色,这里设置为红色 (`#FF0000`)。 - `<corners>` 标签用于设置圆角半径,`android:radius` 属性指定了四个角的圆角半径为 `10dp`。 ### 为不同的角设置不同的圆角半径 如果需要为不同的角设置不同的圆角半径,可以使用 `<corners>` 标签的以下属性: - `android:topLeftRadius`:左上角的圆角半径。 - `android:topRightRadius`:右上角的圆角半径。 - `android:bottomLeftRadius`:左下角的圆角半径。 - `android:bottomRightRadius`:右下角的圆角半径。 ```xml <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FF0000" /> <corners android:topLeftRadius="20dp" android:topRightRadius="10dp" android:bottomLeftRadius="5dp" android:bottomRightRadius="15dp" /> </shape> ``` ### 在布局文件中使用圆角形状 创建好圆角形状的 XML 文件后,可以在布局文件中使用它。例如,将一个 `TextView` 的背景设置圆角形状: ```xml <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="Rounded Corner Text" android:background="@drawable/rounded_corner" /> ``` 在上述代码中,`android:background` 属性指定了 `TextView` 的背景为 `@drawable/rounded_corner`,即之前创建的圆角形状文件。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值