今天處理了把iOS6版本改為iOS7的過(guò)程了,遇到了一些問(wèn)題,查了一些資料,紀(jì)錄一下:
成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的長(zhǎng)子網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!1,iPad1上,更新圖標(biāo)以后最后先把原有程序卸載了,要不然圖片殘留很嚴(yán)重,還遇到一個(gè)問(wèn)題說(shuō)是調(diào)試過(guò)程中有其他進(jìn)程在調(diào)試,重啟iPad1就好了。就因?yàn)閳D片殘留的問(wèn)題,至少耽擱我1-2小時(shí)。
2,UINavigationBar自定義:看看支持到4.3的解法:
#pragma mark - #pragma mark 自定義導(dǎo)航欄背景 @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的圖片,還得我自己來(lái)裁一下。我個(gè)人比較喜歡注釋掉的方法。上面的函數(shù)是其他同事實(shí)現(xiàn)的公有方法。
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 圖片轉(zhuǎn)換為uicolor,設(shè)為背景,有點(diǎn)像OpenGL中紋理設(shè)置。
UIColor *circleColorPattern = [UIColor colorWithPatternImage: [UIImage p_w_picpathNamed:@"circle_pattern.png"]];
4.2 圖片轉(zhuǎn)換為類似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個(gè)像素,中間那個(gè)像素拉伸活者壓縮。
iOS5之前的方法:
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
這個(gè)方法有局限性,它只能指定leftCapWidth和topCapHeight,然后只有一個(gè)像素能夠重復(fù),也就是rightCapWidth為 p_w_picpathWidth-leftCapWidth-1,而bottomCapHeight為 p_w_picpathHeight - topCapHeight -1,所以重復(fù)的始終是中間的那一個(gè)像素.
最后摘錄一份iOS6,7的適配文章,這文章已經(jīng)看過(guò)2遍以上,可是需要的時(shí)候還要查,所以放在這里。
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.