为按钮添加边框和阴影 [英] Add border and shadow to the buttons

查看:87
本文介绍了为按钮添加边框和阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我在iPad应用程序中添加的按钮添加中等厚度的黑色边框和阴影。我已将这些按钮视为自定义,因为我已在其上应用了图像。如何添加边框和阴影

I want to add medium thick black border and shadow to the buttons that I have added in my iPad application. I have taken those buttons as custom as I have applied images on them. How can I add border and shadow to ht

推荐答案

添加阴影和边框很简单。

To add shadows and border is simple.

1)将QuartzCore框架添加到目标。

2)在要添加边框和阴影的类中导入框架头。 (或者如果您有按钮的自定义类,那么您可以在该类中简单地导入此框架。)

3)要向按钮添加边框,请使用此代码(其中按钮是一个 IBOutlet 与界面中的按钮连接):

1) Add the QuartzCore framework to your target.
2) Import the framework header in the class where you want to add borders and shadows. (Or if you have custom class for the button then you can simple import this framework in that class.)
3) To add the border to the button use this code (where button is an IBOutlet connected with the button in interface):

[self.button.layer setBorderWidth:3.0];
[self.button.layer setBorderColor:[[UIColor blackColor] CGColor]];



4)要将阴影添加到按钮,请使用以下代码:


4) To add the shadow to the button use the following code:

[self.button.layer setShadowOffset:CGSizeMake(5, 5)];
[self.button.layer setShadowColor:[[UIColor blackColor] CGColor]];
[self.button.layer setShadowOpacity:0.5];

您可以使用这些值并查看它将如何影响行为。

You can play around with the values and see how it will affect the behaviour.

这篇关于为按钮添加边框和阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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