如何创建像 iPhone 邮件应用程序中那样的 UIToolBar 最新更新标签

发布于 2024-10-08 06:37:23 字数 1256 浏览 0 评论 0原文

所以我有一个带有“标签”(实际上是 UIBarButtonItem)的 UIToolbar,如下所示:

>使用界面生成器并在工具栏中放置一个 UIBarButton 项并将样式设置为“plain”。然而,正如标题所说,我试图复制iPhone邮件应用程序底部的文本,所以首先我需要更改字体大小和字体类型。我该怎么办呢?这是相关代码:

- (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];

}

我知道我可能需要并排三个不同的标签来解释邮件应用程序标签中字体粗细(粗体/非粗体?)的变化。不过,在继续之前,我想尝试根据自己的喜好进行修改。

另外,我想知道如何使“标签”不可点击。如果我使用 setEnabled:NO 文本会变灰,这不是我想要的。我想要的只是点击“标签”时不出现点击动画。

提前致谢!

编辑:

所以我最终使用以下代码创建了一个标签:

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];

结果如下:

alt text

但是,我希望标签的背景不是白色,更具体地说,我希望背景清晰,以便工具栏的灰色阴影显示出来。但是我在 UILabel 文档中没有找到任何背景属性。有人知道如何去做这件事吗?谢谢!

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

alt text

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 "label" 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:

alt text

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叫嚣ゝ 2024-10-15 06:37:23

您应该使用包含 UILabel 的自定义栏按钮项目作为自定义视图。这样,您可以通过标签的属性更改字体大小等。

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

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];
︶葆Ⅱㄣ 2024-10-15 06:37:23

UILabel是UIView的子类,它有一个backgroundColor属性。只需调用label.backgroundColor = [UIColorclearColor];

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文