今天处理了把iOS6版本改为iOS7的过程了,遇到了一些问题,查了一些资料,纪录一下:
成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的长子网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!1,iPad1上,更新图标以后最后先把原有程序卸载了,要不然图片残留很严重,还遇到一个问题说是调试过程中有其他进程在调试,重启iPad1就好了。就因为图片残留的问题,至少耽搁我1-2小时。
2,UINavigationBar自定义:看看支持到4.3的解法:
#pragma mark - #pragma mark 自定义导航栏背景 @implementation UINavigationBar (CustomImage) - (UIImage *)barBackground { UIImage *bg = [UIImage p_w_picpathNamed:@"bg_navbar_ios7.png"]; if ([FMUSystem getOSVersion] < 7.0) { bg = [FMUImage p_w_picpathByScalingAndCroppingForSize:CGSizeMake(320, 44) SourceImage:bg CropType:FMUIMAGE_SCALE_TYPE_FITMIN]; // UIGraphicsBeginImageContext(CGSizeMake(320,44)); // CGContextRef context = UIGraphicsGetCurrentContext(); // [bg drawInRect: CGRectMake(0, 0, 320,44)]; // bg = UIGraphicsGetImageFromCurrentImageContext(); // UIGraphicsEndImageContext(); } return bg; } - (void)didMoveToSuperview { //iOS5 only if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault]; } } //this doesn't work on iOS5 but is needed for iOS4 and earlier - (void)drawRect:(CGRect)rect { //draw p_w_picpath [[self barBackground] drawInRect:rect]; } @end
为了支持iOS7,使用320*64的图片,还得我自己来裁一下。我个人比较喜欢注释掉的方法。上面的函数是其他同事实现的公有方法。
3,生成圆形图
3.1 layer层画圆角
UIImageView * p_w_picpathView = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"oiuyfdsa.png"]]; p_w_picpathView.frame = CGRectMake(20.f, 20.f, 100.f, 100.f); p_w_picpathView.layer.masksToBounds = YES; p_w_picpathView.layer.cornerRadius = 50;
3.2 画布画
-(UIImage*) circleImage:(UIImage*) p_w_picpath withParam:(CGFloat) inset { UIGraphicsBeginImageContext(p_w_picpath.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); CGRect rect = CGRectMake(inset, inset, p_w_picpath.size.width - inset * 2.0f, p_w_picpath.size.height - inset * 2.0f); CGContextAddEllipseInRect(context, rect); CGContextClip(context); [p_w_picpath drawInRect:rect]; CGContextAddEllipseInRect(context, rect); CGContextStrokePath(context); UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newimg; }
4,图片平铺的方式
4.1 图片转换为uicolor,设为背景,有点像OpenGL中纹理设置。
UIColor *circleColorPattern = [UIColor colorWithPatternImage: [UIImage p_w_picpathNamed:@"circle_pattern.png"]];
4.2 图片转换为类似android中9.png的方式
iOS5之后:
UIImage *buttonBackgroundImage = [[UIImage p_w_picpathNamed:@"button_bkg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,13,0,13)]; [button setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal];
这是取27个像素,中间那个像素拉伸活者压缩。
iOS5之前的方法:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
这个方法有局限性,它只能指定leftCapWidth和topCapHeight,然后只有一个像素能够重复,也就是rightCapWidth为 p_w_picpathWidth-leftCapWidth-1,而bottomCapHeight为 p_w_picpathHeight - topCapHeight -1,所以重复的始终是中间的那一个像素.
最后摘录一份iOS6,7的适配文章,这文章已经看过2遍以上,可是需要的时候还要查,所以放在这里。
Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest version of iOS introduces lots of visual changes. From a developer’s perspective, the navigation bar and status bar are two noticeable changes that need to cater. The status bar is now transparent, that means the navigation bar behind it shows through. In some cases, the background p_w_picpath for a navigation bar can extend up behind the status bar.
Some time ago, I’ve written a tutorial about how to customize a navigation bar. I think it’s time to revisit the customization and see how it is done in iOS 7. Here are some of the tips and tricks that you’ll find in this article:
Setting the background color of navigation bar
Using background p_w_picpath in navigation bar
Customizing the color of back button
Changing the font of navigation bar title
Adding multiple bar button items
Changing the style of status bar
Hiding the status bar
You’ll need Xcode 5 to properly execute the code as presented in this tutorial. So if you’re still using older versions of Xcode, make sure you upgrade to Xcode 5 before running the sample Xcode project.
Before we go in to the customization, let’s first take a look at the default navigation bar generated by Xcode 5 and iOS 7. Simply create a Xcode project using Single View Controller template. Embed the view controller in a navigation controller. If you don’t want to start from scratch, you can justdownload this sample Xcode project.
Xcode 5 bundles both iOS 6 and iOS 7 Simulators. Try to run the sample project using both versions of Simulators.
As you can see, the navigation bar in iOS 7 is by default intertwined with the status bar. The default color is also changed to light gray, as well.
In iOS 7, the tintColor property is no longer used for setting the color of the bar. Instead, use the barTintColor property to change the background color. You can insert the below code in the didFinishLaunchingWithOptions: of AppDelegate.m.
1 另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。 网站栏目:iOSUIImage/UIImageView处理-创新互联 文章链接:http://bjjierui.cn/article/cshdjc.html 其他资讯
|