开发者

How To Create UIToolBar Latest Update Label Like That Found in the iPhone's Mail App

开发者 https://www.devze.com 2023-01-31 15:54 出处:网络
so I have a UIToolbar with a \"label\"(actually a UIBarButtonItem) on it like so: To make it I used interface builder and placed a UIBarButton item in the tool bar and set the style to \"plain\". H

so I have a UIToolbar with a "label"(actually a UIBarButtonItem) on it like so:

How To Create UIToolBar Latest Update Label Like That Found in the iPhone's Mail App

To make it I used interface builder and placed a UIBarButton item in the tool bar and set the style to "plain". However, as the title says, I am trying to replicate the text at the bottom of the iPhone's mail app, so firstly I need to change the font size and font type. How would I go about that? Here is the relevant code:

- (void)viewDidLoad {
    [super viewDidLoad];

    lastUpdateLabel.title = @"Last updated...";//lastUpdateLabel is of type UIBarButtonItem  

    [self.view addSubview:self.navigationController.view];

    [self.navigationController.view setFrame:self.view.frame];

}

I am aware that I will probably need three different labels side-by-side to account for the change in font thickness(bold/unbold?) in the Mail app's label. However, I would like to try modifying one to my liking before continuing.

Also, I am wondering how to make the "lab开发者_如何学编程el" unclickable. If I use setEnabled:NO the text gets greyed-out which is not what I want. All I want is for the clicking animation to not appear when the "label" is tapped.

Thanks in advance!

EDIT:

So I have ended up creating a label with the following code:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 20.0f)];
    label.text = @"last updated...";
    label.textColor = [UIColor colorWithWhite:0.5 alpha:1.0];
    label.font = [UIFont systemFontOfSize:13.0];
    label.userInteractionEnabled = NO;

    [lastUpdateLabel initWithCustomView:label];
    [label release];

And it results in this:

How To Create UIToolBar Latest Update Label Like That Found in the iPhone's Mail App

However, I want the background of the label to not be white, more specifically I want the background to be clear so that the shades of grey of the tool bar shows through. However I didn't find any background attribute in the UILabel documentation. Anyone know of how to go about doing this? Thanks!


You should use a custom bar buttom item that contains a UILabel as a custom view. That way, you can change the font size etc. through the label's properties.

UILabel *label = [[[UILabel alloc] initWithFrame:myFrame] autorelease];
...
UIBarButtonItem *statusItem = [[[UIBarButtonItem alloc] initWithCustomView:label] autorelease];
myToolbar.items = [NSArray arrayWithObject:statusItem];


The UILabel is a subclass of UIView, which has a backgroundColor property. Just call label.backgroundColor = [UIColor clearColor];.

0

精彩评论

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