代码之家  ›  专栏  ›  技术社区  ›  Rudiger

UIButton仅背景略透明

  •  3
  • Rudiger  · 技术社区  · 14 年前

    我知道我可以做一个定制的,但我想会有一个更简单的方法

    1 回复  |  直到 14 年前
        1
  •  1
  •   tc.    14 年前

    使用以下内容渲染空白按钮:

    UIGraphicsBeginImageContextWithOptions(size,0,0);
    [button.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    从这里开始,将alpha减半就不难了(在提取图像之前,在“DestOver”混合模式下用50%不透明的rect填充它?)。然后将其设置为自定义按钮的背景。

    或者,可以直接修改视图层次结构中的视图;不建议这样做,因为它往往会突破操作系统版本。