UIImageView 获取图片的 宽 高
2015-10-29 08:55
393 查看
需要的切图 是@2X @3X 的 我之前一般是 根据@2X 的图 比例 除以2 得到的尺寸 设置 imageView .frame 比如 : //@2X 图片大小如果是 80 * 80 UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)]; imageView.image = [UIImage imageNamed:@“icon_button”]; 这么做 要提前去查看这张图片的大小 写出imageView要设置的size 尺寸 现在 可以这么做 UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_button "]]; imageView.frame = CGRectSetX(imageView.frame, 10); imageView.frame = CGRectSetY(imageView.frame, 10); 这样就可以了 根本不需要知道图片到底多大 帅气 imageView = [[UIImageView alloc]initWithImage:[UIImageimageNamed:@"icon_button"]]; 这个方法 的意思 等同于: UIImage *img = [UIImage imageNamed:@"icon_button"]; UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.width)]; //于是 再设置 这个imageView的相对位置就好了
相关文章推荐
- error:unknown filesystem grub rescue
- JDBC中Statement接口提供的execute、executeQuery和executeUpdate之间的区别
- 通用固定长度编码格式的字符串查找算法的实现
- UI基础之 --------- UITableView
- SpriteBuilder中节点位置类型为百分比时不能定位的解决
- SpriteBuilder中节点位置类型为百分比时不能定位的解决
- SpriteBuilder中节点位置类型为百分比时不能定位的解决
- 桌面虚拟化,你还担心什么?
- extensions添加的方法是requires
- iOS输入框UITextView随键盘UIkeyboard弹出与消失改变Rect
- How the performance impacts your revenue-性能影响营收
- iOS学习之UINavigationController详解与使用(三)ToolBar
- iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
- UINavigationController导航控制器一
- LeetCode——Unique Path
- easyui-combobox---ajax获取数据库JSON数据,实现搜索框实时显示模糊搜索结果
- UIColor的RGB定义颜色(灰色)
- 基于EasyUI的Web开发框架
- java集合框架 arrayblockingqueue应用分析
- 怎么设置UITableView Cell之间的距离