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

标签 iphone image ios4 uinavigationbar

我需要设置 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/

相关文章:

iphone - 正则表达式从/* by AUTHOR 中提取作者 */

java - 如何在swing中制作图像查看器?

java - 如何将 Bitmap ArrayList 保存到文件

lua/torch 中的 image.display 窗口

ios - 如何为 iOS 应用程序创建自签名 ipa?

iphone - 如何用项目构建ZBar SDK而不是使用静态库?

iphone - 添加到 ALAssetGroup 时 ALAsset 的自定义文件名

iphone - MKMapView 处置

jquery - iPhone jQuery : How to implement a Split view in iPad using Jquery Mobile + phone gap in iPhone

iphone - UINavigationController 不显示 Root View Controller