iOSUIImage/UIImageView處理-創(chuàng)新互聯(lián)

今天處理了把iOS6版本改為iOS7的過程了,遇到了一些問題,查了一些資料,紀(jì)錄一下:

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的長子網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

   1,iPad1上,更新圖標(biāo)以后最后先把原有程序卸載了,要不然圖片殘留很嚴(yán)重,還遇到一個問題說是調(diào)試過程中有其他進(jìn)程在調(diào)試,重啟iPad1就好了。就因?yàn)閳D片殘留的問題,至少耽擱我1-2小時。

   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的圖片,還得我自己來裁一下。我個人比較喜歡注釋掉的方法。上面的函數(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個像素,中間那個像素拉伸活者壓縮。

    iOS5之前的方法:

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth
topCapHeight:(NSInteger)topCapHeight;

  這個方法有局限性,它只能指定leftCapWidth和topCapHeight,然后只有一個像素能夠重復(fù),也就是rightCapWidth為 p_w_picpathWidth-leftCapWidth-1,而bottomCapHeight為 p_w_picpathHeight - topCapHeight -1,所以重復(fù)的始終是中間的那一個像素.

  最后摘錄一份iOS6,7的適配文章,這文章已經(jīng)看過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

iOS UIImage/UIImageView處理

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.

Default Navigation Bar in iOS 7

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.

iOS UIImage/UIImageView處理

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.

Changing the Background Color of Navigation Bar

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

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

名稱欄目:iOSUIImage/UIImageView處理-創(chuàng)新互聯(lián)
文章源于:http://muchs.cn/article22/cshdjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、面包屑導(dǎo)航外貿(mào)建站、全網(wǎng)營銷推廣網(wǎng)站設(shè)計公司、企業(yè)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

<object id="stxo8"></object>