Swift:删除Aspect Fit ImageView中的空白空格

时间:2015-12-06 19:26:12

标签: ios swift uiimageview uiimage

如何删除一些小图像之前和之后的空白空格。

有些图像效果很好,如下图所示,有些图像在图像上方和下方有很大的空间。 我使用Parse所以我想我无法直接访问imageView:

// upload Image To Parse as PFImageView
   let imgFile = object?.objectForKey("ImgView") as? PFFile
        cell.ImgView.file = imgFile
        cell.questionImgView.loadInBackground()
       // cell.questionImgView.clipsToBounds = true
      cell. cell.ImgView.clipsToBounds.contentMode = UIViewContentMode.ScaleAspectFit

enter image description here

1 个答案:

答案 0 :(得分:-1)

您只需对UIButton执行以下操作即可为其提供多行和不同的字体:

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setAlignment:NSTextAlignmentCenter];
[style setLineBreakMode:NSLineBreakByWordWrapping];

UIFont *font1 = [UIFont fontWithName:@"HelveticaNeue-Medium" size:20.0f];
UIFont *font2 = [UIFont fontWithName:@"HelveticaNeue-Light"  size:20.0f];
NSDictionary *dict1 = @{NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),  
                    NSFontAttributeName:font1};
NSDictionary *dict2 = @{NSUnderlineStyleAttributeName:@(NSUnderlineStyleNone),    
                    NSFontAttributeName:font2};

NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"LINE 1\n"    attributes:dict1]];
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"line 2"      attributes:dict2]];
[[self buttonToStyle] setAttributedTitle:attString forState:UIControlStateNormal];
[[[self buttonToStyle] titleLabel] setNumberOfLines:0];
[[[self buttonToStyle] titleLabel] setLineBreakMode:NSLineBreakByWordWrapping];

来源:iOS NSAttributedString on UIButton