[英]rounded navigation bar image iphone sdk
I am trying to set the navigation bar's titleView
to a rounded image. 我正在尝试将导航栏的
titleView
设置为圆形图像。 Similar to profile images you generally see in messaging applications. 与您通常在消息传递应用程序中看到的个人资料图像相似。
I believe I should be able to create a rounded scaled down image by doing the following: 我相信我可以通过执行以下操作来创建四舍五入的按比例缩小的图像:
UIImageView* profileImageView = [[UIImageView alloc] initWithImage:logoImage];
[profileImageView setFrame:CGRectMake(0, 0, 30, 30)];
//profileImageView.contentMode = UIViewContentModeScaleAspectFit;
// XXX contentMode commented out because enabling it causes the rounded corners to have no effect?
profileImageView.layer.cornerRadius = 15;
profileImageView.layer.masksToBounds = YES;
profileImageView.clipsToBounds = YES;
self.navigationItem.titleView = profileImageView;
This appears to create the image I desire for a split second when I load the emulator, but the image appears in the top left corner of the screen and then immediately snaps to the center of the navigation bar. 加载模拟器时,这似乎可以创建我想要的瞬间图像,但是该图像显示在屏幕的左上角,然后立即捕捉到导航栏的中央。 Once at the center of the navigation bar it rescales to take up the entire space of the navigation bar instead of remaining as a small circle.
一旦位于导航栏的中心,它将重新缩放以占据导航栏的整个空间,而不是保留一个小圆圈。 What I missing?
我想念什么? It seems like I must need to disable what ever mechanism is causing my image to scale up to fill the entire navigation bar.
似乎我必须禁用导致我的图像放大以填充整个导航栏的机制。
Just add it to a contain view 只需将其添加到包含视图
UIView * containView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
UIImageView* profileImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpeg"]];
[profileImageView setFrame:CGRectMake(0, 0, 30, 30)];
profileImageView.layer.cornerRadius = 15;
profileImageView.layer.masksToBounds = YES;
profileImageView.clipsToBounds = YES;
[containView addSubview:profileImageView];
self.navigationItem.titleView = containView;
Screenshot 截图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.