iOS Project development Tips (i)--How to customize Uiviewcontroller's Titile

Source: Internet
Author: User

in project development, we will encounter the need to define the title text style, the system's API self.title It 's hard to customize it, and the previous API has a very complex dictionary property that can be modified and not explained here, so let's look at a simple way to modify its style.

We look at our own viewcontroller.m file.

- (void) viewdidload{[SuperViewdidload];UILabel*label = [[UILabelAlloc] Initwithframe:cgrectmake (0,0, $, +)]; Self. Navigationitem. Titleview= label; Label. Text= @"Home"; Label. TextAlignment=1; Label. Font= [UifontSystemfontofsize: A]; Label. TextColor= [UicolorWhitecolor]; }

In fact, to Navigationitem assigned a titleview, note, here is self.navigationItem.titleView = label; used
Instead of
[self.navigationItem.titleView addSubview label]

If you want all of the Viewcontroller title to have the same style, create a basicviewcontroller inheritance Viewcontroller then write the above code to him, and then leave an interface to pass the title content.

With the above method, you can also successfully avoid the TabItem title above and the first one added to Tabbarviewcontroller viewcontroller title conflict.

iOS Project development Tips (i)--How to customize Uiviewcontroller's Titile

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.