简体   繁体   中英

How do I add a title for my UIToolbar?

please i have just added an UIToolbar to my view with a back button, and i want to put a title to this UIToolbar , in interface builder i can't do it manually so i should add it in the program, how should i do please, my view class is like this :

#import "AproposView.h"


@implementation AproposView

-(IBAction)backMainView{


    [self dismissModalViewControllerAnimated:YES];

}

this back button is in the UItoolbar, so i need just to add a title, THX in advance :)

#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]    

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 202, 23)];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.shadowColor = UIColorFromRGB(0xe5e7eb);
//  label.shadowOffset = CGSizeMake(0, 1);
    label.textColor = UIColorFromRGB(0x717880);
    label.text = @"Edit Classes";
    label.font = [UIFont boldSystemFontOfSize:20.0];
    label.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    label.shadowOffset = CGSizeMake(0, -1.0);
    UIBarButtonItem *toolBarTitle = [[UIBarButtonItem alloc] initWithCustomView:label];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
toolBar.items = [NSArray arrayWithObjects:fixedSpace, toolBarTitle, fixedSpace, nil];

Instead of adding a UILabel to UIToolbar add a UITextField to it as a Bar Button Item and set the required title and disable its UserInteraction. Really simple and easy technique. Sanpshot界面生成器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM