Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

adding title for label #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Classes/ios/MMLabel.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
#import <UIKit/UIKit.h>

@interface MMLabel : UILabel

@property NSString* title;
@property NSString* message;
@end
3 changes: 2 additions & 1 deletion Classes/ios/MMPopLabel.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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<MMPopLabelDelegate> delegate;

+ (MMPopLabel *)popLabelWithText:(NSString *)text;
+ (MMPopLabel *)popLabelWithTitle:(NSString *)title andMessage:(NSString *)message;
- (void)addButton:(UIButton *)button;
- (void)popAtView:(UIView *)view;
- (void)dismiss;
Expand Down
29 changes: 19 additions & 10 deletions Classes/ios/MMPopLabel.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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])
{
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down