>我将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
解决方法
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.