From ab0acd8ec6cb7207e51be647ffa86ce1dae9b015 Mon Sep 17 00:00:00 2001 From: Lucas Vidal Date: Thu, 12 Feb 2015 18:27:10 -0300 Subject: [PATCH] Allow initializing popup with attributed string --- Classes/ios/MMPopLabel.h | 2 ++ Classes/ios/MMPopLabel.m | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Classes/ios/MMPopLabel.h b/Classes/ios/MMPopLabel.h index f3bdcb2..0d738da 100644 --- a/Classes/ios/MMPopLabel.h +++ b/Classes/ios/MMPopLabel.h @@ -25,6 +25,8 @@ @property (nonatomic, weak) id delegate; ++ (MMPopLabel *)popLabelWithAttributedString:(NSAttributedString *)attributedString; + + (MMPopLabel *)popLabelWithText:(NSString *)text; - (void)addButton:(UIButton *)button; diff --git a/Classes/ios/MMPopLabel.m b/Classes/ios/MMPopLabel.m index df8199d..580994b 100644 --- a/Classes/ios/MMPopLabel.m +++ b/Classes/ios/MMPopLabel.m @@ -51,6 +51,13 @@ @interface MMPopLabel () @implementation MMPopLabel ++ (MMPopLabel *)popLabelWithAttributedString:(NSAttributedString *)attributedString { + MMPopLabel *popLabel = [[MMPopLabel alloc] initWithAttributedString: attributedString]; + + + return popLabel; + +} + (MMPopLabel *)popLabelWithText:(NSString *)text { @@ -59,6 +66,30 @@ + (MMPopLabel *)popLabelWithText:(NSString *)text return popLabel; } +- (instancetype)initWithAttributedString: (NSAttributedString *)attributedString { + if (self = [super initWithFrame:CGRectZero]) + { + self.buttons = [@[] mutableCopy]; + + self.backgroundColor = [UIColor clearColor]; + self.hidden = YES; + + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self.tipSize = 24; + } else { + self.tipSize = 12; + } + + self.label = [[MMLabel alloc] initWithFrame:CGRectZero]; + self.label.textAlignment = NSTextAlignmentCenter; + self.label.attributedText = attributedString; + self.label.backgroundColor = [UIColor clearColor]; + self.label.numberOfLines = 0; + + [self addSubview:self.label]; + } + return self; +} - (id)initWithText:(NSString *)text {