diff --git a/Classes/ios/MMLabel.h b/Classes/ios/MMLabel.h old mode 100644 new mode 100755 index c4770e2..f599748 --- a/Classes/ios/MMLabel.h +++ b/Classes/ios/MMLabel.h @@ -9,5 +9,6 @@ #import @interface MMLabel : UILabel - +@property NSString* title; +@property NSString* message; @end diff --git a/Classes/ios/MMPopLabel.h b/Classes/ios/MMPopLabel.h old mode 100644 new mode 100755 index 9626160..57338b7 --- a/Classes/ios/MMPopLabel.h +++ b/Classes/ios/MMPopLabel.h @@ -22,10 +22,11 @@ @property (nonatomic, retain) UIColor *labelTextHighlightColor UI_APPEARANCE_SELECTOR; @property (nonatomic, retain) UIFont *labelFont UI_APPEARANCE_SELECTOR; @property (nonatomic, retain) UIFont *buttonFont UI_APPEARANCE_SELECTOR; +@property (nonatomic, retain) UIFont *titleFont UI_APPEARANCE_SELECTOR; @property (nonatomic, weak) id delegate; -+ (MMPopLabel *)popLabelWithText:(NSString *)text; ++ (MMPopLabel *)popLabelWithTitle:(NSString *)title andMessage:(NSString *)message; - (void)addButton:(UIButton *)button; - (void)popAtView:(UIView *)view; - (void)dismiss; diff --git a/Classes/ios/MMPopLabel.m b/Classes/ios/MMPopLabel.m old mode 100644 new mode 100755 index 5aa5769..ebfedda --- a/Classes/ios/MMPopLabel.m +++ b/Classes/ios/MMPopLabel.m @@ -52,15 +52,14 @@ @interface MMPopLabel () @implementation MMPopLabel -+ (MMPopLabel *)popLabelWithText:(NSString *)text ++ (MMPopLabel *)popLabelWithTitle:(NSString *)title andMessage:(NSString *)message { - MMPopLabel *popLabel = [[MMPopLabel alloc] initWithText:text]; - + MMPopLabel *popLabel = [[MMPopLabel alloc] initWithTitle:title andMessage:message]; return popLabel; } -- (id)initWithText:(NSString *)text +- (id)initWithTitle:(NSString *)title andMessage:(NSString *)message { if (self = [super initWithFrame:CGRectZero]) { @@ -74,10 +73,11 @@ - (id)initWithText:(NSString *)text } else { self.tipSize = 12; } - + self.label = [[MMLabel alloc] initWithFrame:CGRectZero]; self.label.textAlignment = NSTextAlignmentCenter; - self.label.text = text; + self.label.message = message; + self.label.title = [title stringByAppendingString:@"\n\n"]; self.label.backgroundColor = [UIColor clearColor]; self.label.numberOfLines = 0; @@ -105,17 +105,26 @@ - (void)setupAppearance if (!_labelFont) { _labelFont = [UIFont systemFontOfSize:_tipSize]; } - + + if (!_titleFont) { + _titleFont = [UIFont systemFontOfSize:_tipSize + 2.0]; + } + self.label.textColor = _labelTextColor; - self.label.font = _labelFont; + //self.label.font = _labelFont; /* resize label and view */ CGFloat maxWidth = [UIScreen mainScreen].applicationFrame.size.width * 0.80f; CGFloat maxHeight = [UIScreen mainScreen].applicationFrame.size.height * 0.80f; - NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:self.label.text + NSMutableAttributedString *finalText = [[NSMutableAttributedString alloc] initWithString:self.label.title + attributes:@{NSFontAttributeName:_titleFont}]; + NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:self.label.message attributes:@{NSFontAttributeName:_labelFont}]; - CGRect rect = [attributedText boundingRectWithSize:(CGSize){maxWidth, CGFLOAT_MAX} + [finalText appendAttributedString:attributedText]; + self.label.attributedText = finalText; + + CGRect rect = [finalText boundingRectWithSize:(CGSize){maxWidth, CGFLOAT_MAX} options:NSStringDrawingUsesLineFragmentOrigin context:nil]; CGFloat minWidth = MAX(rect.size.width, 180);