【问题标题】:UIButton.titleLabel shadow is clippingUIButton.titleLabel 阴影正在剪裁
【发布时间】:2012-11-29 08:29:08
【问题描述】:

因为 UIButton.titleLabel.shadowOffset 属性使阴影锐利,我改变了 drawTextInRect 方法来创建半​​径如下的自定义阴影:

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
float colorValues[] = {0, 0, 0, opacity};
CGColorRef shadowColor = CGColorCreate(colorSpace, colorValues);
CGSize shadowOffset = CGSizeMake(offsetX, offsetY);
CGContextSetShadowWithColor (context, shadowOffset, radius, shadowColor);

这很好用。它会产生阴影。我更改了 titleLabel 的边界并调用了 drawTextInRect 方法,例如:

button.titleLabel.bounds = CGRectMake(button.titleLabel.bounds.origin.x, button.titleLabel.bounds.origin.y, button.titleLabel.bounds.size.width, button.titleLabel.bounds.size.height);
[button.titleLabel drawTextInRect:button.titleLabel.bounds];
[button setNeedsLayout];

由于 titleLabel 的边界,阴影被剪裁了。

任何帮助将不胜感激...

【问题讨论】:

    标签: objective-c ios uibutton uilabel frame


    【解决方案1】:

    您是否尝试过对图层进行相同操作。我认为它会解决您的问题,并且可能不需要您所做的。

    简单地说,为你的按钮创建 layer(CALayer) 对象并使用你需要的任何属性。记住,使用 layer 你需要导入 QuartzCore 框架。

    试试吧,如有任何问题,请大喊大叫。

    【讨论】:

      猜你喜欢
      • 2013-07-12
      • 1970-01-01
      • 2023-03-27
      • 2022-10-07
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      相关资源
      最近更新 更多