Добавить заголовок и изображение на панель навигации - PullRequest
4 голосов
/ 26 марта 2011

Мне нужно установить имя 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, doonot

Ответы [ 2 ]

8 голосов
/ 28 марта 2011
    // 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];
4 голосов
/ 26 марта 2011

Создание UIView с 2 подпредставлениями: UIImageView и UILabel. Установите titleView для UIView.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...