forked from wujunyang/MobileProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
548 additions
and
619 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
MobileProject/Expand/Category/UIKit/UIButton/UIButton+JKImagePosition.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// UIButton+JKImagePosition.h | ||
// Demo_ButtonImageTitleEdgeInsets | ||
// | ||
// Created by luxiaoming on 16/1/15. | ||
// Copyright © 2016年 luxiaoming. All rights reserved. | ||
// | ||
//https://github.com/Phelthas/Demo_ButtonImageTitleEdgeInsets | ||
// 用button的titleEdgeInsets和 imageEdgeInsets属性来实现button文字图片上下或者左右排列的 | ||
#import <UIKit/UIKit.h> | ||
|
||
typedef NS_ENUM(NSInteger, JKImagePosition) { | ||
LXMImagePositionLeft = 0, //图片在左,文字在右,默认 | ||
LXMImagePositionRight = 1, //图片在右,文字在左 | ||
LXMImagePositionTop = 2, //图片在上,文字在下 | ||
LXMImagePositionBottom = 3, //图片在下,文字在上 | ||
}; | ||
|
||
@interface UIButton (JKImagePosition) | ||
|
||
/** | ||
* 利用UIButton的titleEdgeInsets和imageEdgeInsets来实现文字和图片的自由排列 | ||
* 注意:这个方法需要在设置图片和文字之后才可以调用,且button的大小要大于 图片大小+文字大小+spacing | ||
* | ||
* @param spacing 图片和文字的间隔 | ||
*/ | ||
- (void)jk_setImagePosition:(JKImagePosition)postion spacing:(CGFloat)spacing; | ||
|
||
@end |
54 changes: 54 additions & 0 deletions
54
MobileProject/Expand/Category/UIKit/UIButton/UIButton+JKImagePosition.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// UIButton+JKImagePosition.m | ||
// Demo_ButtonImageTitleEdgeInsets | ||
// | ||
// Created by luxiaoming on 16/1/15. | ||
// Copyright © 2016年 luxiaoming. All rights reserved. | ||
// | ||
|
||
#import "UIButton+JKImagePosition.h" | ||
|
||
@implementation UIButton (JKImagePosition) | ||
|
||
- (void)jk_setImagePosition:(JKImagePosition)postion spacing:(CGFloat)spacing { | ||
CGFloat imageWith = self.imageView.image.size.width; | ||
CGFloat imageHeight = self.imageView.image.size.height; | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" | ||
CGFloat labelWidth = [self.titleLabel.text sizeWithFont:self.titleLabel.font].width; | ||
CGFloat labelHeight = [self.titleLabel.text sizeWithFont:self.titleLabel.font].height; | ||
#pragma clang diagnostic pop | ||
|
||
CGFloat imageOffsetX = (imageWith + labelWidth) / 2 - imageWith / 2;//image中心移动的x距离 | ||
CGFloat imageOffsetY = imageHeight / 2 + spacing / 2;//image中心移动的y距离 | ||
CGFloat labelOffsetX = (imageWith + labelWidth / 2) - (imageWith + labelWidth) / 2;//label中心移动的x距离 | ||
CGFloat labelOffsetY = labelHeight / 2 + spacing / 2;//label中心移动的y距离 | ||
|
||
switch (postion) { | ||
case LXMImagePositionLeft: | ||
self.imageEdgeInsets = UIEdgeInsetsMake(0, -spacing/2, 0, spacing/2); | ||
self.titleEdgeInsets = UIEdgeInsetsMake(0, spacing/2, 0, -spacing/2); | ||
break; | ||
|
||
case LXMImagePositionRight: | ||
self.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth + spacing/2, 0, -(labelWidth + spacing/2)); | ||
self.titleEdgeInsets = UIEdgeInsetsMake(0, -(imageHeight + spacing/2), 0, imageHeight + spacing/2); | ||
break; | ||
|
||
case LXMImagePositionTop: | ||
self.imageEdgeInsets = UIEdgeInsetsMake(-imageOffsetY, imageOffsetX, imageOffsetY, -imageOffsetX); | ||
self.titleEdgeInsets = UIEdgeInsetsMake(labelOffsetY, -labelOffsetX, -labelOffsetY, labelOffsetX); | ||
break; | ||
|
||
case LXMImagePositionBottom: | ||
self.imageEdgeInsets = UIEdgeInsetsMake(imageOffsetY, imageOffsetX, -imageOffsetY, -imageOffsetX); | ||
self.titleEdgeInsets = UIEdgeInsetsMake(-labelOffsetY, -labelOffsetX, labelOffsetY, labelOffsetX); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
} | ||
|
||
@end |
122 changes: 0 additions & 122 deletions
122
MobileProject/Expand/Category/UIKit/UIDevice/UIDevice+Hardware.h
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.