![](/img/trans.png)
[英]Show Blended Layers reveals red UIImage but it does not have an alpha channel
[英]UIButton is partially red when enabling Show Blended Layers
我想通過在適當的情況下使我的視圖不透明來提高性能。 我有一個在模擬器中顯示為紅色的UIButton
- 它只是按鈕文本周圍的紅色,而不是整個框架。 在 Storyboard 中,我啟用了 Opaque 並將背景顏色從透明更改為白色,但它在模擬器中仍然顯示為紅色。
如何將其更改為綠色,使其完全不透明,而不是嘗試使用透明度?
請注意,當您將UILabel
的背景和不透明更改為 YES 時,它是完全綠色的。
我在你的情況下使用以下代碼:
[button.titleLabel setOpaque:YES];
[button.titleLabel setBackgroundColor:[UIColor whiteColor]];
// or which-you-want-color
顯然,您應該保持對按鈕的弱引用。
漂亮的作品。 按鈕大小小於屏幕截圖大小。
我相信 UIButton 由幾個視圖組成,例如 titleLabel。 可以枚舉 UIButtons 的子視圖並將它們設置為不透明。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
for(UIView *subview in [button subviews]){
subview.opaque = YES;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.