IOS 8 Practical Tips (there's always something you don't know and you'll use)

Source: Internet
Author: User

_ Nanshan recalled

Original link: http://www.jianshu.com/p/a3156826c27c

In the development process we always encounter a variety of small problems, some small problems are not very easy to solve, here is the main thing you may not know (of course, it is possible that you know that the great God does not have to look down)

1. Local fillet problem of control

A button or label, as long as the right two corner fillet, or just a rounded corner. What should we do? This will require a layer mask to help us.

CGRect rect = CGRectMake (0, 0, 100, 50);

Cgsize Radio = Cgsizemake (5, 5);//Fillet size

Uirectcorner Corner = uirectcornertopleft| uirectcornertopright;//this fillet position

Uibezierpath *path = [Uibezierpath bezierpathwithroundedrect:rect byroundingcorners:corner CornerRadii:radio];

Cashapelayer *masklayer = [[Cashapelayer alloc]init];//Create Shapelayer

Masklayer.frame = Button.bounds;

Masklayer.path = path. cgpath;//Setting the path

Button.layer.mask = Masklayer;

For example, a button, other controls that inherit from UIView can

2, Navigationbar of transparency issues

If you just set the alpha of Navigationbar to 0, it would be tantamount to hiding the navigationbar, and as you all know, the parent view's alpha is set to 0, then the child views are all transparent. Then the corresponding Navigationbar title and the left and right two buttons will disappear. This obviously does not reach the effect we demand.

(1) If you just want to navigationbar transparent, the buttons and headings are available in the following ways:

[Self.navigationController.navigationBar setbackgroundimage:[uiimage New]

forbarmetrics:uibarmetricsdefault];//set an empty background image to Navigationbar to make it transparent, and the caption buttons are

Careful you will find a line like this:

This requires us to do further processing, the line is removed, the following methods can be:

Self.navigationController.navigationBar.shadowImage = [UIImage new];

In fact, this line is also image control. Set to Empty

(2) If you want to achieve on a transparent basis, depending on the pull-off distance, the transparency becomes opaque, then the above one seems to be out of reach, which requires us to use another method

Navigationbar is a composite view, it has a lot of controls, so we can start with his internal

[[Self.navigationController.navigationBar subviews] Objectatindex:0].alpha = 0;// This allows you to set alpha based on the offset of the scrollview to achieve a gradual and transparent effect.

3. Global Settings Navigationbar heading style and Baritem heading styles

Uicolorwithhexrgb () This method is defined by itself, it just needs to give a color.

[[Uinavigationbar appearance] Setbartintcolor:uicolorwithhexrgb (0xfefefe)];

[[Uinavigationbar appearance] Settitletextattributes:@{nsfontattributename:[uifont boldSystemFontOfSize:18], Nsforegroundcolorattributename:uicolorwithhexrgb (0XFE6D27)}];

[[Uitabbaritem appearance] Settitletextattributes:@{nsfontattributename: [Uifont boldsystemfontofsize:10], Nsforegroundcolorattributename:uicolorwithhexrgb (0x666666)} Forstate:uicontrolstatenormal];

[[Uitabbaritem appearance] Settitletextattributes:@{nsfontattributename: [Uifont boldsystemfontofsiz

4, Navigationbar hidden display of excessive

One page hides Navigationbar, the other is not hidden. Two pages for push and pop, especially when there is a slide gesture return, do not do processing will cause the slide return, the Navigationbar position is empty, directly display a black or display the following layer of view, it is difficult to see. This requires us to add excessive animations to hide or show Navigationbar:

The page that will appear after the return implementation Viewwillappear method, need to hide is set to Yes, need to display is set to No

-(void) Viewwillappear: (BOOL) animated{

[Super viewwillappear:animated];

[Self.navigationcontroller Setnavigationbarhidden:no Animated:yes];

}

5, to WebView Add Head View

WebView is a composite view that contains a scrollview,scrollview inside is a uiwebbrowserview (responsible for displaying the contents of WebView)

UIView *webbrowserview = self.webview.scrollview.subviews[0];//Get WebView's Webbrowserview

Self.backheadimageview = [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, Kscreenwidth, kScreenWidth*2/3.0)];

[_backheadimageview sd_setimagewithurl:[nsurl URLWithString:self.imageUrl] placeholderimage:[uiimage imagenamed:@ " Placeholderimage "];

[Self.webview Insertsubview:_backheadimageview BelowSubview:self.webView.scrollView];

Insert the Backheadimageview under the ScrollView of WebView.

CGRect frame = self.webBrowserView.frame;

FRAME.ORIGIN.Y = Cgrectgetmaxy (_backheadimageview.frame);

Self.webBrowserView.frame = frame;

Change the height of the Webbrowserview frame down backheadimageview to make it visible

6. Animation settings for modal jumps

Animate the modal jumps with four options available

Detailviewcontroller *DETAILVC = [[Detailviewcontroller alloc]init];

Uimodaltransitionstylefliphorizontal Flip

Uimodaltransitionstylecoververtical Bottom Slide out

Uimodaltransitionstylecrossdissolve fade

Uimodaltransitionstylepartialcurl page

Detailvc.modaltransitionstyle = Uimodaltransitionstylepartialcurl;

[Self PRESENTVIEWCONTROLLER:DETAILVC animated:yes completion:nil];

7, picture processing only to get part of the picture

UIImage *image = [UIImage imagenamed:filename];

Cgimageref imageref = image. Cgimage;

CGRect rect = CGRectMake (origin.x, ORIGIN.Y, Size.width, size.height);

The width height here is relative to the real size of the picture

For example, your picture is 400x400 then (0,0,400,400) is the full size of the picture, want to take which part of the corresponding coordinates can be set

Cgimageref imagerefrect = Cgimagecreatewithimageinrect (imageref, rect);

UIImage *imagerect = [[UIImage alloc] initwithcgimage:imagerefrect];

8. Set the picture for UIView

UIImage *image = [UIImage imagenamed:@ "playing"];

_layerview.layer.contents = (__bridge ID) image. Cgimage;

_layerview.layer.contentscenter = CGRectMake (0.25, 0.25, 0.5, 0.5);

You can also set the displayed picture range

But here are slightly different, here the four values are between 0-1; the correspondence is still written x,y,widt,height

IOS 8 Practical Tips (there's always something you don't know and you'll use)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.