开发者

How do I add a title for my UIToolbar?

开发者 https://www.devze.com 2023-02-17 08:43 出处:网络
please i have just added an UIToo开发者_开发知识库lbar 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 t

please i have just added an UIToo开发者_开发知识库lbar 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.

How do I add a title for my UIToolbar?

0

精彩评论

暂无评论...
验证码 换一张
取 消