如何实现自定义UIView像UIAlertView一样全屏覆盖
2016-07-03
展开全部
直观上来看,通过一个UIView配合图片,或者半透明的颜色都可以,这样的确可以简单的实现这个过程。但是比较推荐使用通过Quartz2D去实现这个功能,涉及到图片素材的加载,还是有性能影响的。IO过程耗费比较高。贴一个实现:-(void)drawRect:(CGRect)rect{CGContextRefcontext=UIGraphicsGetCurrentContext();CGRectcurrentBounds=self.bounds;CGGradientRefbackgroundGradient;size_tnum_locations=2;CGFloatlocations[2]={0.0,1.0};CGFloatcomponents[8]={0.0,0.0,0.0,0.0,//Startcolor0.0,0.0,0.0,0.6};//EndcolorCGColorSpaceRefrgbColorspace=CGColorSpaceCreateDeviceRGB();backgroundGradient=CGGradientCreateWithColorComponents(rgbColorspace,components,locations,num_locations);CGPointcenterPoint=CGPointMake(CGRectGetMidX(currentBounds),CGRectGetMidY(currentBounds));CGContextDrawRadialGradient(context,backgroundGradient,centerPoint,0.0,centerPoint,currentBounds.size.width,kCGGradientDrawsAfterEndLocation);CGGradientRelease(backgroundGradient);}在UIView子类的drawRect中实现即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询