如何在UIButton中创建边框? [英] How to create border in UIButton?

查看:131
本文介绍了如何在UIButton中创建边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用名为addButton的自定义按钮,我想用白色边框,我如何在自定义按钮周围获得白色边框?

I use custom button in my app named "addButton" and I want to border it with white color how can i get the white color border around my custom button?

推荐答案

您可以通过访问按钮的图层属性来设置CALayer上的边框属性。

You can set the border properties on the CALayer by accessing the layer property of the button.

首先,添加Quartz

First, add Quartz

#import <QuartzCore/QuartzCore.h>

设置属性:

myButton.layer.borderWidth = 2.0f;
myButton.layer.borderColor = [UIColor greenColor].CGColor;

参见:

https://developer.apple.com/documentation/quartzcore/calayer#/ / apple_ref / occ / cl / CALayer

上面链接中的CALayer允许您设置角半径,maskToBounds等其他属性......

The CALayer in the link above allows you to set other properties like corner radius, maskToBounds etc...

另外,关于按钮乐趣的好文章:

Also, a good article on button fun:

https://web.archive.org/web/20161221132308/http://www.apptite.be/ tutorial_custom_uibuttons.php

这篇关于如何在UIButton中创建边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆