gpt4 book ai didi

iphone - 将标题和图像添加到导航栏

转载 作者:行者123 更新时间:2023-12-03 19:05:03 24 4
gpt4 key购买 nike

我需要设置 UIViewController 的名称和导航栏的图像。到目前为止,我可以显示图像,但标题当然丢失了。

    // show image
UIImage *image = [UIImage imageNamed: @"bar_icon.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
imageView.frame = CGRectMake(0, 0, 40, 40);
self.navigationItem.titleView = imageView;
[imageView release];

感谢您的帮助,
BR,不要

最佳答案

    // show image
UIImage *image = [UIImage imageNamed: @"bar_icon.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
imageView.frame = CGRectMake(70, 0, 40, 40);

// label
UILabel *tmpTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 100, 40)];
tmpTitleLabel.text = @"Mannschaft";
tmpTitleLabel.backgroundColor = [UIColor clearColor];
tmpTitleLabel.textColor = [UIColor whiteColor];

CGRect applicationFrame = CGRectMake(0, 0, 300, 40);
UIView * newView = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
[newView addSubview:imageView];
[newView addSubview:tmpTitleLabel];
self.navigationItem.titleView = newView;

[imageView release];
[tmpTitleLabel release];

关于iphone - 将标题和图像添加到导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5441945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com