相关疑难解决方法(0)

UINavigationBar自定义标题位置

我有一个定制的UINavigationBar(不同的大小,背景等),在自定义标题视图中.我使用此代码来实现此目的:

UIView * mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    mainView.backgroundColor = [UIColor yellowColor];

    UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0,kScreenWidth,80)];
    navBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    UINavigationItem *currentItem = [[UINavigationItem alloc] init];
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont fontWithName:@"Helvetica-Bold" size: 30.0];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:self.title];
    [label sizeToFit];
    [currentItem setTitleView:label];
    [label release];

    [navBar pushNavigationItem:currentItem animated:NO];
    [currentItem release];

    [mainView addSubview:navBar];
    [navBar release];    

    self.view = mainView;
[mainView release];
Run Code Online (Sandbox Code Playgroud)

但是,我现在的问题是,即使正确添加了自定义标题视图,它也不会与NavBar垂直居中.我错过了什么?

谢谢!

iphone cocoa-touch objective-c

23
推荐指数
1
解决办法
2万
查看次数

如何垂直居中UICollectionView内容

我试图动态地居中UICollectionView的内容,但是现有的解决方案都没有考虑到每行可能有多个单元格的事实.

在UINavigationBar中尝试过这个中心自定义标题?以及这里的两个解决方案:UICollectionView垂直居中,无济于事.

我很惊讶iOS默认情况下无法做到这一点,甚至更多的是无法获得当前显示的行数(这也解决了我的问题).此外,我无法获得内容的大小(而不仅仅是框架的大小),这也有助于我实现所需的效果.

我有这个:

 --------
|X X X X |
|X X X X |
|        |
|        |
 --------
Run Code Online (Sandbox Code Playgroud)

但我想要这个:

 --------
|        |
|X X X X |
|X X X X |
|        |
 --------
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,

非常感谢.

ios swift swift2

9
推荐指数
2
解决办法
6843
查看次数

标签 统计

cocoa-touch ×1

ios ×1

iphone ×1

objective-c ×1

swift ×1

swift2 ×1