1
目前,我在滾動視圖中將多個UIView的角落半徑和陰影應用於多個UIView。我注意到,添加角落半徑和陰影會使scrollview每當我滾動時就像瘋狂一樣滯後。我如何應用這些影響而不會讓我的表現受到影響?如何將角點半徑應用到UIView中沒有問題?
目前,我在滾動視圖中將多個UIView的角落半徑和陰影應用於多個UIView。我注意到,添加角落半徑和陰影會使scrollview每當我滾動時就像瘋狂一樣滯後。我如何應用這些影響而不會讓我的表現受到影響?如何將角點半徑應用到UIView中沒有問題?
嘗試也設置層的shadowPath
:
view.layer.cornerRadius=6.0f;
view.layer.borderWidth=2.0f;
view.layer.borderColor=[UIColor grayColor].CGColor;
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOpacity = 0.3f;
view.layer.shadowOffset = CGSizeMake(0, 0.0f);
view.layer.masksToBounds = NO;
UIBezierPath *path = [UIBezierPath bezierPathWithRect:view.bounds];
view.layer.shadowPath = path.CGPath;
+(UIImage *)makeRoundCornerImage : (UIImage*) img : (int) cornerWidth : (int) cornerHeight
{
UIImage * newImage = nil;
if(nil != img)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int w = img.size.width;
int h = img.size.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextBeginPath(context);
CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
addRoundedRectToPath(context, rect, cornerWidth, cornerHeight);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
[img release];
newImage = [[UIImage imageWithCGImage:imageMasked] retain];
CGImageRelease(imageMasked);
[pool release];
}
return newImage;
}
用這種方法的幫助下,我們可以創建任何PNG文件
UIImage *imageFromFile = [UIImage imageNamed:@"FilterFields.png"];
imageFromFile = [ImageManipulator
makeRoundCornerImage:imageFromFile : 10 : 10];
[SmallTable setImage:imageFromFile];
什麼是圓角// ImageManipulator? – 2013-05-14 02:09:48