【问题标题】:Applying shadow on uibutton Makes the button text blury在 uibutton 上应用阴影使按钮文本模糊
【发布时间】:2016-06-06 10:56:32
【问题描述】:

这是我在使用 .XIB 文件创建的 uibutton 上添加阴影的代码

UIBezierPath *shadowPathEndbtn = [UIBezierPath bezierPathWithRect:CGRectMake(0,  self->_navigationView.frame.size.height - 70,[UIScreen mainScreen].bounds.size.width , 2)];
    self->_EndButton.layer.masksToBounds = NO;

    self->_EndButton.layer.shadowColor = [UIColor blackColor].CGColor;
    self->_EndButton.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
    self->_EndButton.layer.shadowOpacity = 0.7f;
    self->_EndButton.layer.shouldRasterize = YES;
    self->_EndButton.layer.shadowPath = shadowPathForEndbtn.CGPath;

我可以使用此代码设置阴影,但此代码使我的按钮文本看起来模糊。我无法弄清楚这背后的确切原因。任何帮助表示赞赏!

【问题讨论】:

    标签: ios objective-c iphone uibutton uibezierpath


    【解决方案1】:
    self->_EndButton.layer.masksToBounds = false            
    self->_EndButton.layer.shadowColor = [UIColor blackColor].CGColor
    self->_EndButton.layer.contentsScale = [[UIScreen mainScreen]scale];
    self->_EndButton.layer.shadowOpacity = 0.7f;
    self->_EndButton.layer.shadowRadius = 10.0;
    self->_EndButton.layer.shadowOffset = CGSizeMake(0,0)
    

    这会产生阴影,而且测试也不模糊

    【讨论】:

    • 是什么让按钮文字看起来模糊?
    • 阴影路径,由于 UIBezierPath 导致文字模糊
    【解决方案2】:

    设置按钮背景颜色

    self.EndButton.BackgroundColor=[UIColor WhiteColor];
    

    【讨论】:

      猜你喜欢
      • 2013-12-16
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多