UIImageView xib里面拉伸图片技巧
来源:互联网 发布:腾讯认证域名生成器 编辑:程序博客网 时间:2024/04/19 19:38
拉伸图片的时候代码里和xib里面的图片名字去掉@2x,但是原始图片文件得要xxx@2x.png
The X and Y values seem to be the positions for the stretch starting point, relative to the entire width and height of the image, i.e. 0.5 would mean a point in the middle of the image.
Same thing for the Width and Height: sizes for the stretchable area, relative to the image size, i.e. setting it to a value of 1 / imageWidth would mean the stretchable area is 1 pixel wide. The strange thing is 0 also work fine for the blue pill button (could be for convenience reasons?).
Below, view modes are set to "Scale to Fill". The images are stretchable images fromhttps://github.com/0xced/UIKit-Artwork-Extractor.
This answer was inspired by http://www.slideshare.net/mystcolor/stretchable-images-in-uiimageview-
In cases where you want more than one pixel to stretch (ie. a pattern in the center of the button) the stretchable UIImage does not work.
The UIButton's contentStretch does also not work properly.
How I solved it: I subclassed UIButton and added a UIImageView *backgroundImageView
as property and placed it at index 0 as a subview within the UIButton
. I then ensure in layoutSubviews that it fits the button entirely and set the highlighted states of the imageView. All you need to do is handover a UIImageView with the correct contentStretch and contentMode applied.
.h file
@interface ButtonWithBackgroundImage : UIButton { UIImageView *backgroundImageView;}@property (retain) UIImageView *backgroundImageView;+ (ButtonWithBackgroundImage*)button;@end
.m file
@implementation ButtonWithBackgroundImage@synthesize backgroundImageView;+ (ButtonWithBackgroundImage*)button {return [self buttonWithType:UIButtonTypeCustom];}- (void)setBackgroundImageView:(UIImageView*)img { [backgroundImageView removeFromSuperview]; [backgroundImageView release]; backgroundImageView = [img retain]; if(backgroundImageView){ [self insertSubview:backgroundImageView atIndex:0]; [self setNeedsLayout]; }}- (void)setSelected:(BOOL)select { [super setSelected:select]; // we subclass the setSelect method to highlight the background imageview[backgroundImageView setHighlighted:select||self.highlighted];}- (void)setHighlighted:(BOOL)highl { [super setHighlighted:highl]; // we subclass the setHighlighted method to highlight the background imageview [backgroundImageView setHighlighted:highl||self.selected];}- (void)layoutSubviews { [super layoutSubviews]; self.backgroundImageView.frame = self.bounds;}- (void)dealloc { [backgroundImageView release]; backgroundImageView = nil; [super dealloc];}@end
- UIImageView xib里面拉伸图片技巧
- UIImageView的图片拉伸
- uiimageView 的图片拉伸问题的解决办法
- uiimageView 的图片拉伸问题的解决办法
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- IOS图片拉伸技巧
- iOS图片拉伸技巧
- IOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- iOS图片拉伸技巧
- 求关键路径(包含邻接表的建立、拓扑排序)
- Data Structures (Weiss) Chapter 3: The Queue ADT, Pointer
- log4cpp第一个程序HelloWorld
- 深度优先搜索
- baoloiu
- UIImageView xib里面拉伸图片技巧
- 拓扑排序
- Linux设备模型之input子系统详解
- OpenMp
- Java实现递归经典案例——三角数字的多种实现方式
- c++容器1(vector、list、deque)
- Linux LCD驱动中的LCD参数
- Java jasypt对.properties配置文件密码加密
- [Gitiles]Git服务器的一键式搭建