DaidoujiChen лет назад: 12
Родитель
Сommit
61a483928d

+ 21 - 34
Classes/Editing/Argument Input Views/FLEXArgumentInputFontsPickerView.m

@@ -22,19 +22,9 @@
 {
     self = [super initWithArgumentTypeEncoding:typeEncoding];
     if (self) {
-        
-        [self createAvailableFonts];
-        
         self.targetSize = FLEXArgumentInputViewSizeSmall;
-        
-        self.inputTextView.inputView = ({
-            UIPickerView *fontsPicker = [UIPickerView new];
-            fontsPicker.dataSource = self;
-            fontsPicker.delegate = self;
-            fontsPicker.showsSelectionIndicator = YES;
-            fontsPicker;
-        });
-        
+        [self createAvailableFonts];
+        self.inputTextView.inputView = [self createFontsPicker];
     }
     return self;
 }
@@ -42,15 +32,12 @@
 - (void)setInputValue:(id)inputValue
 {
     self.inputTextView.text = inputValue;
-
     if ([self.availableFonts indexOfObject:inputValue] == NSNotFound) {
         [self.availableFonts insertObject:inputValue atIndex:0];
     }
-    
     [(UIPickerView*)self.inputTextView.inputView selectRow:[self.availableFonts indexOfObject:inputValue]
                                                inComponent:0
                                                   animated:NO];
-    
 }
 
 - (id)inputValue
@@ -60,18 +47,23 @@
 
 #pragma mark - private
 
+- (UIPickerView*)createFontsPicker
+{
+    UIPickerView *fontsPicker = [UIPickerView new];
+    fontsPicker.dataSource = self;
+    fontsPicker.delegate = self;
+    fontsPicker.showsSelectionIndicator = YES;
+    return fontsPicker;
+}
+
 - (void)createAvailableFonts
 {
     NSMutableArray *unsortedFontsArray = [NSMutableArray array];
-
     for (NSString *eachFontFamily in [UIFont familyNames]) {
-        
         for (NSString *eachFontName in [UIFont fontNamesForFamilyName:eachFontFamily]) {
             [unsortedFontsArray addObject:eachFontName];
         }
-        
     }
-    
     self.availableFonts = [NSMutableArray arrayWithArray:[unsortedFontsArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];
 }
 
@@ -84,32 +76,27 @@
 
 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
 {
-    
     return [self.availableFonts count];
-    
 }
 
 #pragma mark - UIPickerViewDelegate
 
 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
 {
-    
+    UILabel *fontLabel;
     if (!view) {
-        view = [UILabel new];
-        [(UILabel*)view setBackgroundColor:[UIColor clearColor]];
-        [(UILabel*)view setTextAlignment:NSTextAlignmentCenter];
+        fontLabel = [UILabel new];
+        fontLabel.backgroundColor = [UIColor clearColor];
+        fontLabel.textAlignment = NSTextAlignmentCenter;
+    } else {
+        fontLabel = (UILabel*)view;
     }
-    
     UIFont *font = [UIFont fontWithName:self.availableFonts[row] size:15.0];
-    NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObject:font
-                                                                     forKey:NSFontAttributeName];
+    NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
     NSAttributedString *attributesString = [[NSAttributedString alloc] initWithString:self.availableFonts[row] attributes:attributesDictionary];
-    
-    [(UILabel*)view setAttributedText:attributesString];
-    [view sizeToFit];
-    
-    return view;
-    
+    fontLabel.attributedText = attributesString;
+    [fontLabel sizeToFit];
+    return fontLabel;
 }
 
 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

+ 10 - 9
Classes/Editing/Argument Input Views/FLEXArgumentInputTextView.m

@@ -30,13 +30,7 @@
         self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
         self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
         self.inputTextView.delegate = self;
-        self.inputTextView.inputAccessoryView = ({
-            UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
-            UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
-            UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(textViewDone)];
-            toolBar.items = @[spaceItem, doneItem];
-            toolBar;
-        });
+        self.inputTextView.inputAccessoryView = [self createToolBar];
         [self addSubview:self.inputTextView];
     }
     return self;
@@ -44,11 +38,18 @@
 
 #pragma mark - private
 
+- (UIToolbar*)createToolBar
+{
+    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
+    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
+    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(textViewDone)];
+    toolBar.items = @[spaceItem, doneItem];
+    return toolBar;
+}
+
 - (void)textViewDone
 {
-    
     [self.inputTextView resignFirstResponder];
-    
 }