ios - 如何给UIButton设置3d效果

标签 ios swift uibutton background-color

您好,我正在尝试为 UIButton 设置 3d 效果,但我的代码设置不正确。

是这样的

enter image description here

但我的要求如下

enter image description here

你能帮我一个吗?

我的代码如下:

self.submitBtn1.backgroundColor = [self colorWithHexString:@"a53129"];
self.submitBtn1.layer.cornerRadius = 3.0;
self.submitBtn1.layer.borderWidth = 2.0;
self.submitBtn1.layer.borderColor = [[UIColor clearColor] CGColor];

最佳答案

使用下面的代码实现,设置按钮类型为自定义

self.submitBtn.backgroundColor = [UIColor colorWithRed:(200.0f/255.0f) green:0.0 blue:0.0 alpha:1.0];

self.submitBtn.layer.cornerRadius = 3.0;

self.submitBtn.layer.borderWidth = 2.0;
self.submitBtn.layer.borderColor = [[UIColor clearColor] CGColor];

self.submitBtn.layer.shadowColor = [UIColor colorWithRed:(100.0f/255.0f) green:0.0 blue:0.0 alpha:1.0].CGColor;
self.submitBtn.layer.shadowOpacity = 1.0f;
self.submitBtn.layer.shadowRadius = 1.0f;
self.submitBtn.layer.shadowOffset = CGSizeMake(0, 3);

我附上图片,显示这段代码的结果。

enter image description here

关于ios - 如何给UIButton设置3d效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33009270/

相关文章:

ios - 在帧 ios 内移动图像

ios - 在 NSURLSessionData 的实现中未调用委托(delegate)方法

ios - 通过 ViewController 导航时声音停止

ios - 在 swift 3 中更改图标位置

ios - 获取用户的通知设置

swift - 如何在应用程序包之外的 AVPlayer 中播放视频文件

iOS:重新生成 UIImageView

ios - 如何防止 dequeueReusableCellWithIdentifier 重复我的段选择?

ios - Swift:UIButton textLabel.text 值在 switch 语句中不可用

ios - 在 TableView Cell 创建中向 UIButton 分配操作