• UI: 在导航栏显示一张图片


    问题:
    在导航控制器的当前视图中的标题中用一张图片代替文本 
    使用导航项目中视图控制器中 navigation item 的 titleView 属性: 
    - (void)viewDidLoad{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    /* Create an Image View to replace the Title View */ 
    UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 40.0f)];
     imageView.contentMode = UIViewContentModeScaleAspectFit;
     /* Load an image. Be careful, this image will be cached */
    UIImage *image = [UIImage imageNamed:@"FullSizeLogo.png"]; 
    /* Set the image of the Image View */
    [imageView setImage:image];
    /* Set the Title View */
    self.navigationItem.titleView = imageView;
    }
    如果你想使用文本,可以使用导航项目的 title 属性。然而,如果要更多控制标题或者要在导航栏简单显示图片或者其他视图,可以使用视图控制器的导航项目中 titleView 属 性。
    可以对其赋值任意UIView的子类对象,例如,我们创建了一个image view,并赋值了一个图片给它,然后把它作为导航控制器上当前视图控制器的标题显示出来。 
  • 相关阅读:
    树链剖分求LCA
    洛谷P1019 单词接龙
    洛谷P1441 砝码称重
    洛谷P2347 砝码称重
    洛谷P1164 小A点菜
    洛谷P2202 [USACO13JAN]方块重叠Square Overlap
    黑客与画家 第四章
    黑客与画家 第十二章
    记录最近一段的体会
    11.5最小生成树(Minimum Spanning Trees)
  • 原文地址:https://www.cnblogs.com/safiri/p/4018923.html
Copyright © 2020-2023  润新知