实现方法 iOS提供了简单的方法来设置不被拉伸的区域,是以图片原本大小上对应区域来设置的,方法为: - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets...)capInsets resizingMode:(UIImageResizingMode)resizingMode 这个方法第一个参数接受一个UIEdgeInsets对象,用来说明你要限制不被拉伸的区域...,其包含四个参数,分别为图片中距离上、左、下、右边界的不拉伸部分的范围宽度: UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right...上面的方法中第二个参数表示拉伸的模式: UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片 UIImageResizingModeTile...:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图片 我们通过设置后,可以得到确保右下角不被拉伸的效果: 图中上面的是没做设置的,下面是做了设置的,可以看出效果很明显。
@param edge e.g. edge为UIEdgeInsetsMake(10, 10, 10, 10)时,按钮响应区域上下左右分别扩大10 */ - (void)setTouchEdge:(UIEdgeInsets...#import @interface UIButton () @property (assign, nonatomic,setter=frw_setEdge:) UIEdgeInsets...@selector(hitTest:withEvent:), @selector(es_hitTest:withEvent:)); }); } - (void)setTouchEdge:(UIEdgeInsets...return [self es_hitTest:point withEvent:event]; } } #pragma mark - get & set - (UIEdgeInsets...return [(NSValue *)objc_getAssociatedObject(self, _cmd) UIEdgeInsetsValue]; } - (void)frw_setEdge:(UIEdgeInsets
3、区域的拉伸 - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets; 这个函数需要设置一个UIEdgeInsets参数,UIEdgeInsets...结构体如下: typedef struct UIEdgeInsets { CGFloat top, left, bottom, right; } UIEdgeInsets; 它分别对用了图片进行拉伸的区域距离顶部...比如,一个10*10像素的图片,将UIEdgeInsets参数全部设置为1,则实际拉伸的部分就是中间的8*8的区域的像素。...4、拉伸模式的设置 - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode
表示扩大 例如: self.btn.hitEdgeInsets = UIEdgeInsetsMake(-3, -4, -5, -6); */ @property(nonatomic, assign) UIEdgeInsets...hitWidthScale"; @implementation UIButton (ClickRange) #pragma mark - set Method -(void)setHitEdgeInsets:(UIEdgeInsets...)hitEdgeInsets{ NSValue *value = [NSValue value:&hitEdgeInsets withObjCType:@encode(UIEdgeInsets)...kHitHeightScale, @(kHitHeightScale), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } #pragma mark - get method -(UIEdgeInsets...)hitEdgeInsets{ NSValue *value = objc_getAssociatedObject(self, kHitEdgeInsets); UIEdgeInsets
** 行间距*/ -(CGFloat)rowMarginInWaterFlowLayout:(YJWaterFlowLayout *)waterFlowLayout; /** 边缘之间的间距*/ -(UIEdgeInsets...YJDefaultColumeMargin = 10; /** 每一行之间的间距*/ static const CGFloat YJDefaultRowMargin = 10; /** 边缘之间的间距*/ static const UIEdgeInsets...rowMargin; /** 每一列之间的间距*/ -(CGFloat)columnMargin; /** 列数*/ -(NSInteger)columnCount; /** 边缘之间的间距*/ -(UIEdgeInsets...self.delegate columnCountInWaterFlowLayout:self]; } else { return YJDefaultColumeCount; } } -(UIEdgeInsets
在UIButton中有三个对EdgeInsets的设置:ContentEdgeInsets、titleEdgeInsets、imageEdgeInsets @property(nonatomic) UIEdgeInsets...and emboss appearance @property(nonatomic) BOOL reversesShadowWhenHighlighted; @property(nonatomic) UIEdgeInsets...UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloatleft, CGFloat bottom, CGFloat right...) { UIEdgeInsets insets = {top,left, bottom, right}; return insets; } self.view.backgroundColor...self centerImageAndTitle: DEFAULT_SPACING]; } @end 后面经过测试,如果button的文字长度变更,会导致图片位置变化,经过多次修改UIEdgeInsets
*/ - (void)layoutSubviews; 内边距 // 设置按钮内容的内边距(影响到imageView和titleLabel) @property(nonatomic) UIEdgeInsets...contentEdgeInsets; // 设置titleLabel的内边距(影响到titleLabel) @property(nonatomic) UIEdgeInsets titleEdgeInsets...; // 设置imageView的内边距(影响到imageView) @property(nonatomic) UIEdgeInsets imageEdgeInsets; 图片拉伸...topCapHeight:(NSInteger)topCapHeight; iOS5开始 //传入左上右下不拉伸的区域,默认方式是平铺 - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets...)capInsets; //resizingMode 拉伸方式的参数 - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode
大道至简,直接上代码 -(void)setButtonContentCenter:(UIButton *) btn { CGSize imgViewSize,titleSize,btnSize; UIEdgeInsets...titleEdge]; } 重点参考: iOS UIButton 设置图片文字垂直排列 http://my.oschina.net/sayonala/blog/198376 iOS - UIButton(UIEdgeInsets
UIButtonTypeContactAdd, //废弃 UIButtonTypeRoundedRect = UIButtonTypeSystem, }; 二、属性设置 @property(nonatomic) UIEdgeInsets...包括title和image,可以用如下方法设置 btn.contentEdgeInsets=UIEdgeInsetsMake(20, 20, 0, 0); @property(nonatomic) UIEdgeInsets...@property(nonatomic) BOOL reversesTitleShadowWhenHighlighted; //按钮高亮时,是否改变阴影效果 @property(nonatomic) UIEdgeInsets
contentInset和contentOffset contentSize是contentView的大小 contentInset就相当于html中的padding,是view相对于子view的距离有四个属性 例如UIEdgeInsets...contentOffset是scrollview当前显示区域顶点相对于frame顶点的偏移量 假如有一个ScrollView(scrollViewA),设置scrollViewA的contentInset为UIEdgeInsets
设置整个collectionView的内边距:sectionInset,类型是UIEdgeInsets结构体。...UIEdgeInsets包括:top(上边界),left(左边界),bottom(下边界),right(右边界)4个成员。...UIEdgeInsetsMake函数可以创建UIEdgeInsets结构体实例。 设置每一行之间的间距:minimumLineSpacing。...collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ } 复制代码 //动态设置每个分区的EdgeInsets - (UIEdgeInsets
topCapHeight:(NSInteger)topCapHeight __TVOS_PROHIBITED - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets...- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode...self.view addSubview:imageView]; Screenshot (19).png 再说说第二个方法: - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets
iOS在处理这种图片,也是非常方便的,有相关的系统函数可以做处理, - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode...函数需要传入两个参数,capInsets,resizingMode, capInsets: UIEdgeInsets{CGFloat top, left, bottom, right}, 定义了受保护区域...)data; /// 获取点九图bitmap中的可拉伸区域,如果返回UIEdgeInsetsZero,则表示没有可以拉伸的区域 /// 点九图可能包含多个不连续的可拉伸区域,本函数只取第一个 - (UIEdgeInsets...[1].intValue; if(xEnd < xStart || yEnd < yStart) { return UIEdgeInsetsZero; } UIEdgeInsets...} @end 使用上也比较简单, PNGNinePatch *ninePatch = [PNGNinePatch ninePatchWithPNGFileData:imageFileData]; UIEdgeInsets
copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0); //设置视图Margin @property (nonatomic, readwrite) UIEdgeInsets...@end @implementation MyView //这个方法返回箭头宽度 + (CGFloat)arrowBase{ return 20; } //这个方法中返回内容视图的偏移 +(UIEdgeInsets...property (nullable, nonatomic, copy) UIColor *backgroundColor; //设置Margin @property (nonatomic, readwrite) UIEdgeInsets
setTitleShadowColor:[UIColor purpleColor] forState:UIControlStateNormal]; //button 一些其他属性 @property(nonatomic) UIEdgeInsets...contentEdgeInsets; 内容内距离 @property(nonatomic) UIEdgeInsets titleEdgeInsets; 标题内距离 @property(nonatomic...默认为NO @property(nonatomic) UIEdgeInsets imageEdgeInsets; 图片内边距 @property(nonatomic) BOOL adjustsImageWhenHighlighted
headerReferenceSize; 设置尾视图尺寸大小 @property (nonatomic) CGSize footerReferenceSize; 设置分区的EdgeInset @property (nonatomic) UIEdgeInsets...UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath; 动态设置每个分区的EdgeInsets - (UIEdgeInsets
MWFontIcon.yuedufuHuodeIcon.rawValue, size: CGSize(width: 30.0, height: 50.0), color: UIColor.cyan, edgeInsets: UIEdgeInsets...MWFontIconInt.yuedufuHuodeIcon.rawValue, size: CGSize(width: 30.0, height: 50.0), color: UIColor.blue, edgeInsets: UIEdgeInsets
(UIEvent *)event{ CGPoint convertPoint = [self convertPoint:point toView:self.superview]; UIEdgeInsets
/6.内容视图的大小 @property(nonatomic) CGSize contentSize; //7.内容视图的距离,是从封闭的滚动视图插图 @property(nonatomic) UIEdgeInsets...property(nonatomic) BOOL showsVerticalScrollIndicator; //17.滚动指标点到滚动视图的边缘的距离 @property(nonatomic) UIEdgeInsets...@property(nonatomic) CGSize contentSize; 这个属性用来表示UIScrollView内容的尺寸,滚动范围(能滚多远) @property(nonatomic) UIEdgeInsets
tv.backgroundColor = UIColor.clear // 为了计算正确计算文本高度,需特殊设置textView属性,如下 tv.contentInset = UIEdgeInsets
领取专属 10元无门槛券
手把手带您无忧上云