ios – UIView属性的opaque,alpha和backgroundColor之间的关系是什么?

ios – UIView属性的opaque,alpha和backgroundColor之间的关系是什么?,第1张

概述例如: >我将UIView的alpha属性设置为alpha = 0,这是否意味着其不透明属性被视为opaque = YES? >如何不透明,alpha和backgroundColor影响性能? 还有别的吗? 类似的问题 > UIView performance: opaque, backgroundColor, clearsContextBeforeDrawing? > Is UIView’s o 例如:

>我将UIVIEw的Alpha属性设置为Alpha = 0,这是否意味着其不透明属性被视为opaque = YES?
>如何不透明,Alpha和backgroundcolor影响性能?
还有别的吗?

类似的问题

> UIView performance: opaque,backgroundColor,clearsContextBeforeDrawing?
> Is UIView’s opaque property with a value of YES in conflict with its backgroundColor property with a value of [UIColor clearColor]?
> Cocoa/iPhone: BackgroundColor and Opaque Properties

解决方法 backgroundcolor是出现在UIVIEw背面的颜色的特殊色调.默认情况下,它为零,导致UIVIEw的清晰背景颜色.要为您的UIVIEw分配背景,请分配一个UIcolor,如下所示:
myVIEw.backgroundcolor = [UIcolor greencolor];

您也可以将backgroundcolor设置为图像:

myVIEw.backgroundcolor = [UIcolor colorWithPatternImage:[UIImage imagenamed@"myImage"]];

Alpha是视图的不透明度.您可以使用此属性来淡化UIVIEw并使其部分透明.该值可以从0(完全不可见)到1(完全不透明).

opaque是一个布尔值,表示UIVIEw是否不透明.如果您将Alpha设置为小于1的字符,那么您应该将opaque设置为NO:

myVIEw.opaque = NO;

苹果的documentation解释了为什么和如何不透明的属性的工作原理:

This property provIDes a hint to the drawing system as to how it
should treat the vIEw. If set to YES,the drawing system treats the
vIEw as fully opaque,which allows the drawing system to optimize some
drawing operations and improve performance. If set to NO,the drawing
system composites the vIEw normally with other content. The default
value of this property is YES.

An opaque vIEw is expected to fill its bounds with entirely opaque content—that is,the content should have an Alpha value of 1.0. If the vIEw is opaque and either does not fill its bounds or contains wholly or partially transparent content,the results are unpredictable. You should always set the value of this property to NO if the vIEw is fully or partially transparent.

总结

以上是内存溢出为你收集整理的ios – UIView属性的opaque,alpha和backgroundColor之间关系是什么?全部内容,希望文章能够帮你解决ios – UIView属性的opaque,alpha和backgroundColor之间的关系是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1095830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存