Browse Source

sidebar menu: simplify autolayout code

Felix Paul Kühne 9 years ago
parent
commit
01a105d719
2 changed files with 12 additions and 25 deletions
  1. 3 22
      Sources/VLCSidebarViewCell.m
  2. 9 3
      Sources/VLCWiFiUploadTableViewCell.m

+ 3 - 22
Sources/VLCSidebarViewCell.m

@@ -14,32 +14,13 @@
 
 @implementation VLCSidebarViewCell
 
-- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+{
     if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
         self.clipsToBounds = YES;
         self.backgroundColor = [UIColor clearColor];
-        self.selectedBackgroundView = [[UIView alloc] init];
-        self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
-
-        self.imageView.contentMode = UIViewContentModeCenter;
-
-        self.textLabel.font = [UIFont systemFontOfSize:([UIFont systemFontSize] * 1.2f)];
-        self.textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
-        self.textLabel.shadowColor = [UIColor VLCDarkTextShadowColor];
+        self.selectionStyle =  UITableViewCellSelectionStyleNone;
         self.textLabel.textColor = [UIColor whiteColor];
-        self.textLabel.adjustsFontSizeToFitWidth = YES;
-        self.textLabel.minimumScaleFactor = 0.5f;
-        self.textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
-
-        UILabel *textLabel = self.textLabel;
-        textLabel.translatesAutoresizingMaskIntoConstraints = NO;
-        UIImageView *imageView = self.imageView;
-        imageView.translatesAutoresizingMaskIntoConstraints = NO;
-
-        NSDictionary *dict = NSDictionaryOfVariableBindings(textLabel,imageView);
-        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView(50)]-==8-[textLabel]|" options:0 metrics:0 views:dict]];
-        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView(50)]|" options:0 metrics:0 views:dict]];
-        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[textLabel]|" options:0 metrics:0 views:dict]];
     }
     return self;
 }

+ 9 - 3
Sources/VLCWiFiUploadTableViewCell.m

@@ -60,7 +60,7 @@
     [self.titleLabel sizeToFit];
 
     self.clipsToBounds = YES;
-    self.backgroundColor = [UIColor clearColor];
+    self.backgroundColor = [UIColor VLCMenuBackgroundColor];
     self.selectionStyle =  UITableViewCellSelectionStyleNone;
 
     self.uploadAddressLabel = [UILabel new];
@@ -84,17 +84,23 @@
 {
     UIView *spacer1 = [UIView new];
     UIView *spacer2 = [UIView new];
+    UIView *spacer3 = [UIView new];
+    UIView *spacer4 = [UIView new];
     spacer1.translatesAutoresizingMaskIntoConstraints = NO;
     spacer2.translatesAutoresizingMaskIntoConstraints = NO;
+    spacer3.translatesAutoresizingMaskIntoConstraints = NO;
+    spacer4.translatesAutoresizingMaskIntoConstraints = NO;
     [self.contentView addSubview:spacer1];
     [self.contentView addSubview:spacer2];
+    [self.contentView addSubview:spacer3];
+    [self.contentView addSubview:spacer4];
 
-    NSDictionary *dict = NSDictionaryOfVariableBindings(_titleLabel, _uploadAddressLabel, _serverOnButton, spacer1, spacer2);
+    NSDictionary *dict = NSDictionaryOfVariableBindings(_titleLabel, _uploadAddressLabel, _serverOnButton, spacer1, spacer2, spacer3, spacer4);
     
     [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_serverOnButton(50)]-==8-[_titleLabel]" options:0 metrics:0 views:dict]];
     [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_serverOnButton(50)]-==8-[_uploadAddressLabel]" options:0 metrics:0 views:dict]];
     [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[spacer1][_titleLabel]-==0-[_uploadAddressLabel(>=0)][spacer2(==spacer1)]|" options:0 metrics:0 views:dict]];
-    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_serverOnButton(50)]|" options:0 metrics:0 views:dict]];
+    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[spacer3][_serverOnButton(50)][spacer4]|" options:0 metrics:0 views:dict]];
 }
 
 - (void)netReachabilityChanged