开发者

Add title and image to navigationbar

开发者 https://www.devze.com 2023-02-19 17:45 出处:网络
I need so set the name of the UIViewController and an image to the navigationBar. So far I am able to display the image, but the title is of course missing.

I need so set the name of the UIViewController and an image to the navigationBar. So far I am able to display the image, but the title is of course missing.

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

Thanks for your help,

BR,开发者_运维问答 doonot


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


Create a UIView with 2 subview: a UIImageView and a UILabel. Set the titleView to the UIView.

0

精彩评论

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