【发布时间】:2015-07-11 01:56:27
【问题描述】:
我正在尝试将导航栏的titleView 设置为圆形图像。类似于您通常在消息传递应用程序中看到的个人资料图像。
我相信我应该能够通过执行以下操作来创建一个缩小的圆形图像:
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;
这似乎是在我加载模拟器时创建我想要的图像,但图像出现在屏幕的左上角,然后立即捕捉到导航栏的中心。一旦到达导航栏的中心,它会重新缩放以占据导航栏的整个空间,而不是保留为一个小圆圈。我错过了什么?似乎我必须禁用导致我的图像放大以填充整个导航栏的机制。
【问题讨论】:
标签: ios objective-c iphone ios7