當前位置:編程學習大全網 - 站長素材 - 如何實現自定義UIView像UIAlertView壹樣全屏覆蓋

如何實現自定義UIView像UIAlertView壹樣全屏覆蓋

直觀上來看,通過壹個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中實現即可。

  • 上一篇:四六級背單詞用什麽軟件?
  • 下一篇:我運動我快樂手抄報的內容
  • copyright 2024編程學習大全網