我有一个图像显示在CGRect。如何在视图中居中?
这是我的代码:
UIImage * image = [UIImage imageNamed:place.image];
CGRect rect = CGRectMake(10.0f, 90.0f, image.size.width, image.size.height);
UIImageView * imageView = [[UIImageView alloc] initWithFrame:rect];
[imageView setImage:image];
我试过imageView.center,但没有效果。
提前致谢。
UIView的中心是一种财产,而不是一种方法。
您需要计算要放入的实际位置。您可以通过设置视图的框架或设置其中心来实现,这在您的情况下更为简单。
你不会说什么视图,然后去make imageView一个子视图。如果你把它放在名为superview的东西,你可以这样做:
CGPoint superCenter = CGPointMake(CGRectGetMidX([superview bounds]), CGRectGetMidY([superview bounds]));
[imageView setCenter:superCenter];
相关文章
- ios - Ipad的CGRect中心
- iphone - CGRect var作为属性值?
- SQL Server查询 - 用DISTINCT选择COUNT(*)
- iphone - 使用文本以编程方式更改UITextView高度
- objective-c - 将UITable中的UITableViewCell中的对象的CGRect转换为相对于self.view的CGRect
- iphone - 以UINavigationItem为中心的标题
- iphone - 如何在NSMutableArray中存储CGRect值?
- iphone - UITextField - (void)drawPlaceholderInRect :( CGRect)rect在iOS 7中返回不同的CGRect高度
转载注明原文:iphone – 以CGRect为中心 - 代码日志