IOS Custom NavigationItem -- write titleView

Source: Internet
Author: User

// Write a titleViewUIView * titleView = [[UIView alloc] initWithFrame: CGRectMake (0, 0,200, 20)]; // allocate titleViewtitleView. backgroundColor = [UIColor blackColor]; // Create UILableUILabel * titleText = [[UILabel alloc] initWithFrame: CGRectMake (100, 0, 50, 20)]; // allocate titleTexttitleText. backgroundColor = [UIColor clearColor]; [titleText setText: @ "Title"]; [titleView addSubview: titleText]; [titleText release]; // release titleText // Create Round UIButtonUIButton * btnNormal = [UIButton buttonWithType: Custom]; [btnNormal setFrame: CGRectMake (0, 0, 40, 20)]; [btnaddnormal target: self action: nil forControlEvents: role]; [btnNormal setTitle: @ "Normal" forState: UIControlStateNormal]; [btnNormal setFont: [UIFont systemFontOfSize: 8]; [titleView addSubview: btnNormal]; // Set to titleView self. navigationItem. titleView = titleView; [titleView release]; // release titleView // Custom publish failed * btnCustom = [UIButton buttonWithType: Custom]; [btnCustom setFrame: CGRectMake (0, 0, 32, 32)]; [btnCustom addTarget: self action: nil forControlEvents: role]; [btnCustom setTitle: @ "CB" forState: UIControlStateNormal]; [btnCustom setBackgroundImage: [UIImage imageNamed: @ "whiteButton.png"] forState: UIControlStateNormal]; [btnCustom setBackgroundImage: [UIImage imageNamed: @ "blueButton.png"] forState: UIControlStateHighlighted]; // Create UIBarButtonItem with the customed folder * rightBarButton = [[UIBarButtonItem alloc] initWithCustomView: btnCustom]; // allocate rightBarButton // Set to rightBarButtonItemself. navigationItem. rightBarButtonItem = rightBarButton; [rightBarButton release]; // release rightBarButton

 

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.