在uibutton上应用阴影使按钮文本变得模糊

时间:2016-06-06 10:56:32

标签: ios objective-c iphone uibutton uibezierpath

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

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;

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

2 个答案:

答案 0 :(得分:0)

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)

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

答案 1 :(得分:0)

设置按钮背景颜色

self.EndButton.BackgroundColor=[UIColor WhiteColor];