Skip to content

Commit

Permalink
1.0.7
Browse files Browse the repository at this point in the history
Add message attribute text
  • Loading branch information
Luo-Kuang committed Nov 27, 2019
1 parent 211791a commit eb20088
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'TargetName' do
pod 'ZFAlertController', '~> 1.0.6'
pod 'ZFAlertController', '~> 1.0.7'
end
```
Then, run the following command:
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'TargetName' do
pod 'ZFAlertController', '~> 1.0.6'
pod 'ZFAlertController', '~> 1.0.7'
end
```
运行:
Expand Down
2 changes: 1 addition & 1 deletion ZFAlertController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "ZFAlertController"
s.version = "1.0.6"
s.version = "1.0.7"
s.summary = "No short description of ZFAlertController."
s.homepage = "https://github.com/FranLucky/ZFAlertController"
s.license = { :type => "MIT"}
Expand Down
3 changes: 2 additions & 1 deletion ZFAlertController/ZFAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef NS_ENUM(NSUInteger, ZFAlertControllerStyle) {
- (UIView *)addCustomView:(zf_CustomView)view config:(zf_CustomViewConfig)config;
- (void)addCustomButton:(zf_CustomButton)view buttonAction:(zf_CustomButtonAction)action config:(zf_CustomViewConfig)config;


- (void)changeMessageText:(NSString *)text attr:(NSDictionary *)attr;

/**
* Background cover color,default [UIColor colorWithWhite:0 alpha:.6]
Expand All @@ -97,6 +97,7 @@ typedef NS_ENUM(NSUInteger, ZFAlertControllerStyle) {

@property(nonatomic, copy) NSString *titleText;
@property(nonatomic, copy) NSString *messageText;

/**
* Nomal CGSizeZero ZFAlertControllerStyleAlert
* height = 0 means auto
Expand Down
23 changes: 20 additions & 3 deletions ZFAlertController/ZFAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ @interface ZFAlertController ()

@property(nonatomic, assign) float titleHeight;
@property(nonatomic, assign) float messageHeight;
@property (nonatomic, strong) NSAttributedString *messageAttributedString;

@property (nonatomic, strong) NSMutableArray *buttonsArray;
@property (nonatomic, strong) NSMutableArray *actionsArray;
Expand Down Expand Up @@ -223,7 +224,7 @@ - (void)viewDidLoad {
if (_titleText.length > 0) {
_titleHeight = [self caclulateHeightWithString:_titleText font:_titleFont];
}
if (_messageText > 0) {
if (_messageText.length > 0 && _messageAttributedString.length == 0) {
_messageHeight = [self caclulateHeightWithString:_messageText font:_messageFont];
}

Expand Down Expand Up @@ -260,7 +261,7 @@ - (void)viewWillLayoutSubviews {
y += self.titleHeight;
}

if (self.messageText.length > 0) {
if (self.messageText.length > 0 || self.messageLabel.attributedText.length > 0) {
if (y == 0) y += self.messageSpace;
y += (self.messageSpace - 5);
[self.messageLabel setFrame:CGRectMake(x, y, contentWidth, self.messageHeight)];
Expand Down Expand Up @@ -517,21 +518,37 @@ - (void)setMessageText:(NSString *)messageText {
_messageLabel.text = messageText;
_messageHeight = [self caclulateHeightWithString:_messageText font:_messageFont];
}

- (void)changeMessageText:(NSString *)text attr:(NSDictionary *)attr {
NSAttributedString *tempStr = [[NSAttributedString alloc] initWithString:text attributes:attr];
_messageLabel.attributedText = tempStr;
_messageHeight = [self caclulateHeightWithString:text attr:attr];
_messageAttributedString = tempStr;
}

- (void)setBackgroudColor:(UIColor *)backgroudColor {
_backgroudColor = backgroudColor;
[self.view setBackgroundColor:_backgroudColor];
}

- (void)setContentBackgroundImage:(UIImage *)contentBackgroundImage {
_contentBackgroundImage = contentBackgroundImage;
self.contentImageView.image = contentBackgroundImage;
}

- (float)caclulateHeightWithString:(NSString *)string font:(UIFont *)font {
return [self caclulateHeightWithString:string attr:@{NSFontAttributeName : font}];
}

- (float)caclulateHeightWithString:(NSString *)string attr:(NSDictionary *)attr {
CGFloat w = NOMAL_ALERT_WIDTH - NOMAL_CONTENT_MARGIN * 2;
if (self.style == ZFAlertControllerStyleActionSheet) w = ZF_SCREEN_WIDTH - NOMAL_CONTENT_MARGIN * 2;
CGSize maxTitleSize = CGSizeMake(w, MAXFLOAT);
float stringHeight = [string boundingRectWithSize:maxTitleSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : font} context:nil].size.height;
float stringHeight = [string boundingRectWithSize:maxTitleSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attr context:nil].size.height;
return ceilf(stringHeight);
}


- (NSString *)keyWithView:(UIView *)view {
return [NSString stringWithFormat:@"%p", view];
}
Expand Down
4 changes: 3 additions & 1 deletion sample/ZFAlertController/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ - (void)viewDidLoad {
}

- (IBAction)buttclick:(UIButton *)sender {
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"alertWithTitle" message:@"" style:ZFAlertControllerStyleAlert];
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"alertWithTitle" message:@"message" style:ZFAlertControllerStyleAlert];
ZFAlertAction *ok = [ZFAlertAction actionWithTitle:@"Ok" action:^{
NSLog(@"ok");
[self testFunc];
}];
ZFAlertAction *cancel = [ZFAlertAction actionWithTitle:@"Cancel" action:^{
NSLog(@"cancel");
}];

alertVC.blankClickDismiss = YES;
if ([sender.titleLabel.text isEqualToString:@"Custom"]) {
// alertVC.backgroudColor = [UIColor redColor];
// alertVC.contentBackgroundColor = [UIColor grayColor];
[alertVC changeMessageText:@"change" attr:@{NSFontAttributeName: [UIFont systemFontOfSize:20]}];
alertVC.contentBackgroundImage = [UIImage imageNamed:@"background"];
alertVC.messageSpace = 20;
alertVC.messageColor = ok.titleColor = alertVC.lineColor = alertVC.titleColor = cancel.titleColor = [UIColor whiteColor];
Expand Down
4 changes: 2 additions & 2 deletions sample/ZFAlertViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 22HHB2G722;
INFOPLIST_FILE = ZFAlertController/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -399,7 +399,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 22HHB2G722;
INFOPLIST_FILE = ZFAlertController/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down

0 comments on commit eb20088

Please sign in to comment.