forked from BigShow1949/BigShow1949
-
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
apple
authored and
apple
committed
Apr 25, 2018
1 parent
34db2d3
commit a5601d8
Showing
11 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
BigShow1949.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file modified
BIN
-2.15 KB
(99%)
BigShow1949.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
BigShow1949/Classes/11 - Tools(常用工具)/UIButton/UIButton+TitlePosition.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,24 @@ | ||
// | ||
// UIButton+TitlePosition.h | ||
// test | ||
// | ||
// Created by apple on 2018/4/4. | ||
// Copyright © 2018年 BigShow. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
typedef NS_ENUM(NSInteger,YFTitleStyle) { | ||
YFTitleStyleTitleOnly = 1, //只显示文字 | ||
YFTitleStyleImgOnly, //只显示图片 | ||
YFTitleStyleLeft, //文字在左,图片在右 | ||
YFTitleStyleRight, //文字在右,图片在左 | ||
YFTitleStyleTop, //文字在上,图片在下 | ||
YFTitleStyleBottom //文字在下,图片在上 | ||
}; | ||
|
||
@interface UIButton (TitlePosition) | ||
|
||
//调用这个方法前,必须先设置好button的image和title/attributedtitle 要不然无法生效 | ||
- (void)layoutTitleWithStyle:(YFTitleStyle)style imageTitleSpace:(CGFloat)space; | ||
@end |
76 changes: 76 additions & 0 deletions
76
BigShow1949/Classes/11 - Tools(常用工具)/UIButton/UIButton+TitlePosition.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,76 @@ | ||
// | ||
// UIButton+TitlePosition.m | ||
// test | ||
// | ||
// Created by apple on 2018/4/4. | ||
// Copyright © 2018年 BigShow. All rights reserved. | ||
// | ||
|
||
#import "UIButton+TitlePosition.h" | ||
|
||
@implementation UIButton (TitlePosition) | ||
|
||
- (void)layoutTitleWithStyle:(YFTitleStyle)style imageTitleSpace:(CGFloat)space { | ||
// self.backgroundColor = [UIColor cyanColor]; | ||
|
||
/** | ||
* 前置知识点:titleEdgeInsets是title相对于其上下左右的inset,跟tableView的contentInset是类似的, | ||
* 如果只有title,那它上下左右都是相对于button的,image也是一样; | ||
* 如果同时有image和label,那这时候image的上左下是相对于button,右边是相对于label的;title的上右下是相对于button,左边是相对于image的。 | ||
*/ | ||
|
||
// 1. 得到imageView和titleLabel的宽、高 | ||
CGFloat imageWith = self.imageView.frame.size.width; | ||
CGFloat imageHeight = self.imageView.frame.size.height; | ||
|
||
CGFloat labelWidth = 0.0; | ||
CGFloat labelHeight = 0.0; | ||
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { | ||
// 由于iOS8中titleLabel的size为0,用下面的这种设置 | ||
labelWidth = self.titleLabel.intrinsicContentSize.width; | ||
labelHeight = self.titleLabel.intrinsicContentSize.height; | ||
} else { | ||
labelWidth = self.titleLabel.frame.size.width; | ||
labelHeight = self.titleLabel.frame.size.height; | ||
} | ||
|
||
// 2. 声明全局的imageEdgeInsets和labelEdgeInsets | ||
UIEdgeInsets imageEdgeInsets = UIEdgeInsetsZero; | ||
UIEdgeInsets labelEdgeInsets = UIEdgeInsetsZero; | ||
|
||
// 3. 根据style和space得到imageEdgeInsets和labelEdgeInsets的值 | ||
switch (style) { | ||
case YFTitleStyleBottom: | ||
{ | ||
imageEdgeInsets = UIEdgeInsetsMake(-labelHeight-space/2.0, 0, 0, -labelWidth); | ||
labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith, -imageHeight-space/2.0, 0); | ||
} | ||
break; | ||
case YFTitleStyleRight: | ||
{ | ||
imageEdgeInsets = UIEdgeInsetsMake(0, -space/2.0, 0, space/2.0); | ||
labelEdgeInsets = UIEdgeInsetsMake(0, space/2.0, 0, -space/2.0); | ||
} | ||
break; | ||
case YFTitleStyleTop: | ||
{ | ||
imageEdgeInsets = UIEdgeInsetsMake(0, 0, -labelHeight-space/2.0, -labelWidth); | ||
labelEdgeInsets = UIEdgeInsetsMake(-imageHeight-space/2.0, -imageWith, 0, 0); | ||
} | ||
break; | ||
case YFTitleStyleLeft: | ||
{ | ||
imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth+space/2.0, 0, -labelWidth-space/2.0); | ||
labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith-space/2.0, 0, imageWith+space/2.0); | ||
} | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
// 4. 赋值 | ||
self.titleEdgeInsets = labelEdgeInsets; | ||
self.imageEdgeInsets = imageEdgeInsets; | ||
} | ||
@end |
13 changes: 13 additions & 0 deletions
13
BigShow1949/Classes/11 - Tools(常用工具)/UIButton/YFButtonCategoryViewController.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,13 @@ | ||
// | ||
// YFButtonCategoryViewController.h | ||
// BigShow1949 | ||
// | ||
// Created by apple on 2018/4/4. | ||
// Copyright © 2018年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface YFButtonCategoryViewController : UIViewController | ||
|
||
@end |
59 changes: 59 additions & 0 deletions
59
BigShow1949/Classes/11 - Tools(常用工具)/UIButton/YFButtonCategoryViewController.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,59 @@ | ||
// | ||
// YFButtonCategoryViewController.m | ||
// BigShow1949 | ||
// | ||
// Created by apple on 2018/4/4. | ||
// Copyright © 2018年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import "YFButtonCategoryViewController.h" | ||
#import "UIButton+TitlePosition.h" | ||
|
||
@interface YFButtonCategoryViewController () | ||
|
||
@end | ||
|
||
@implementation YFButtonCategoryViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.view.backgroundColor = [UIColor whiteColor]; | ||
{ | ||
|
||
UIButton *btn = [[UIButton alloc] init]; | ||
btn.frame = CGRectMake(20, 100, 100, 100); | ||
[btn setTitle:@"title" forState:UIControlStateNormal]; | ||
[btn setImage:[UIImage imageNamed:@"placeholder30"] forState:UIControlStateNormal]; | ||
btn.backgroundColor = [UIColor lightGrayColor]; | ||
[self.view addSubview:btn]; | ||
[btn layoutTitleWithStyle:YFTitleStyleBottom imageTitleSpace:10]; | ||
} | ||
{ | ||
|
||
UIButton *btn = [[UIButton alloc] init]; | ||
btn.frame = CGRectMake(150, 100, 100, 100); | ||
[btn setTitle:@"title" forState:UIControlStateNormal]; | ||
[btn setImage:[UIImage imageNamed:@"placeholder30"] forState:UIControlStateNormal]; | ||
btn.backgroundColor = [UIColor lightGrayColor]; | ||
[self.view addSubview:btn]; | ||
[btn layoutTitleWithStyle:YFTitleStyleTop imageTitleSpace:10]; | ||
} | ||
|
||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
/* | ||
#pragma mark - Navigation | ||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | ||
// Get the new view controller using [segue destinationViewController]. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
@end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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