【问题标题】:Can someone add a gradient to my boring UIButton? [duplicate]有人可以为我无聊的 UIButton 添加渐变吗? [复制]
【发布时间】:2017-03-24 01:32:30
【问题描述】:

我正在努力让渐变层与我的按钮对齐。我希望有人能很快帮助我,这样我的按钮就不会那么糟糕了。

这是我正在使用的:

UIButton *tmpBtn = [[UIButton alloc] initWithFrame:theFrame];

[tmpBtn setTintColor:buttonColor];
[tmpBtn setBackgroundColor:buttonColor];
tmpBtn.layer.cornerRadius = 10;
tmpBtn.layer.borderWidth = 1;
tmpBtn.layer.borderColor = [UIColor blackColor].CGColor;

(buttonColor 被传递到方法中,现在它只是一种颜色)

感谢您的帮助!

【问题讨论】:

    标签: ios objective-c uibutton


    【解决方案1】:

    为您的按钮添加渐变

     CAGradientLayer *gradientLayer = [CAGradientLayer layer];
     gradientLayer.frame = yourButton.layer.bounds;
     gradientLayer.cornerRadius =yourButton.layer.cornerRadius;
     [yourButton.layer addSublayer:gradientLayer];
    

    【讨论】:

    • 为什么要为已经关闭的问题添加答案?
    • 我在它标记为重复之前添加了一个答案
    • 不,您在答案作为副本关闭 11 分钟后添加了答案。查看时间戳。
    • 实际上我是从我的手机 Stackoverflow 应用程序中给出答案的。添加答案后,我编辑了我的答案五次。可能是最后一次编辑的答案时间显示了时间。当我给出答案时,我没有看到标记为重复的问题。真的我不知道
    猜你喜欢
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 2013-01-10
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    相关资源
    最近更新 更多