1111
1212#define FEAlertiOS8Later (floor(NSFoundationVersionNumber ) >= NSFoundationVersionNumber_iOS_8_0)
1313
14+ static inline BOOL FE_checkTextValid (id text) {
15+ if ([text isKindOfClass: [NSString class ]] || [text isKindOfClass: [NSAttributedString class ]]) {
16+ return YES ;
17+ }
18+ return NO ;
19+ }
20+
21+ static inline BOOL FE_isAttributedString (id text) {
22+ if ([text isKindOfClass: [NSAttributedString class ]]) {
23+ return YES ;
24+ }
25+ return NO ;
26+ }
27+
1428@interface FEAlertController ()<UIGestureRecognizerDelegate,FEAlertContentViewDelegate>
1529
1630@property (nonatomic , copy ) FEAlertControllerCallback callback;
@@ -129,8 +143,26 @@ -(FEAlertContentView *)contentView{
129143 if (!_contentView) {
130144 _contentView = [FEAlertContentView instanceWithXIB ];
131145 _contentView.delegate = self;
132- _contentView.titleLabel .text = self.alertTitle ;
133- _contentView.descriptionLabel .text = self.alertDescription ;
146+
147+ if (FE_isAttributedString (self.alertTitle )) {
148+ _contentView.titleLabel .attributedText = self.alertTitle ;
149+ }
150+ else {
151+ _contentView.titleLabel .text = self.alertTitle ;
152+ }
153+
154+ if (FE_isAttributedString (self.alertDescription )) {
155+ _contentView.descriptionLabel .attributedText = self.alertDescription ;
156+ }
157+ else {
158+ // important
159+ if (!_contentView.descriptionLabel .textColor ) {
160+ _contentView.descriptionLabel .textColor = [[FEAlertContentView appearance ] descriptionTextColor ];
161+ }
162+
163+ _contentView.descriptionLabel .text = self.alertDescription ;
164+ }
165+
134166 _contentView.clipsToBounds = YES ;
135167
136168 // image or images
@@ -156,9 +188,9 @@ -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveT
156188
157189+(instancetype )alertWithTitle : (NSString *)title image : (UIImage *)image description : (NSString *)description buttons : (NSArray *)buttons highlightButtonIndex : (NSInteger )highlightButtonIndex callback : (FEAlertControllerCallback)callback {
158190 FEAlertController *alertController = [[FEAlertController alloc ] init ];
159- alertController.alertTitle = title;
191+ alertController.alertTitle = FE_checkTextValid ( title)?title: nil ;
160192 alertController.alertImage = image;
161- alertController.alertDescription = description;
193+ alertController.alertDescription = FE_checkTextValid ( description)?description: nil ;
162194 alertController.alertButtons = buttons;
163195
164196 // highlightButtonIndex
@@ -174,7 +206,6 @@ +(instancetype)alertWithTitle:(NSString *)title image:(UIImage *)image descripti
174206 return alertController;
175207}
176208
177-
178209- (void )showInNewWindow {
179210 // 记录
180211 self.fromWindow = [UIApplication sharedApplication ].keyWindow ;
0 commit comments