澳门威利斯人_威利斯人娱乐「手机版」

来自 网络资讯 2020-05-01 05:34 的文章
当前位置: 澳门威利斯人 > 网络资讯 > 正文

威尼斯娱乐手机版网站:自己搜集的iOS开发经验

这几天市集上绝大大多新闻体现类使用都有用到图像和文字混排,作者事情发生前对那块也是鹘仑吞枣,最近放假适逢其时深远领会一下那块,在那处对此做四个计算,废话非常少说,先上 demo 地址TextKit入门 demo地址精仿手工课 demo地址精仿手工业课博客地址

1、设置UILabel行间距

1. button Logo和文字地点设置
//文字
button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
button.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;```

//图标
[button setImage:[UIImage imageNamed:@"picture_name.png"] forState:UIControlStateNormal];
[button setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 65)];```

在行业内部开班攻读从前,大家先来打听一下图像和文字混排在 iOS地点的上扬,放任 coretext (涉及到某些底部,这里不斟酌State of Qatar不说,苹果在 iOS6给出了*** NSMutableAttributedString其一类,说来讲去正是带属性的字符串,用它能够兑现图像和文字混排,在iOS7苹果则交由了尤其有力的 API--textKit,用 textKit***能够完结特别头昏眼花的分界面,接下去让我们最早浪起来呢

NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString:label.text];

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];

[style setLineSpacing:20];

[attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, label.text.length)];

label.attributedText = attrString;

2. title的设置
self.tabBarItem.title = @"首页";  //只在没有嵌入navigation时生效
self.title = @"新闻";  //self.tabBarItem.title继承自self.title;
self.navigationItem.title = @"导航";  //如果不设置,和self.title的内容是一样的```
#####3. NavigationBar中间文字属性修改

self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont boldSystemFontOfSize:16]
};

#####4. Label部分文字变色

NSString *str = @"this is a string";
NSMutableAttributedString *noteStr =
[[NSMutableAttributedString alloc] initWithString:str];
NSRange redRange = NSMakeRange(0, 20);
[noteStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:redRange];
[label setAttributedText:noteStr];
[label sizeToFit];

#####5. UISwitch修改大小

//不可能安装frame,只好用缩放比例
switch.transform = CGAffineTransformMakeScale(0.75, 0.75);

#####6. 透明NavigationBar

//写法1

  • (void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
    forBarMetrics:UIBarMetricsDefault];
    }
  • (void)viewWillDisappear:(BOOL)animated
    {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setShadowImage:nil];
    [self.navigationController.navigationBar setBackgroundImage:nil
    forBarMetrics:UIBarMetricsDefault];
    }
    威尼斯娱乐手机版网站,//写法2
  • (void)setNavBarImg:(UINavigationBar *)navBar
    {
    if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
    // if iOS 5.0 and later
    [navBar setBackgroundImage:[UIImage imageNamed:@"background_detail_bg1"]
    forBarMetrics:UIBarMetricsDefault];
    }
    else
    {
    UIImageView *imageView = (UIImageView *)[navBar viewWithTag:10];
    [imageView setBackgroundColor:[UIColor clearColor]];
    if (imageView == nil)
    {
    imageView =
    [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background_detail_bg1"]];
    [imageView setTag:10];
    [navBar insertSubview:imageView atIndex:0];
    }
    }
    }
#####7. ScrollView顶部图片下拉变大效果

//以下代码功能是图形高度改善,宽度也会变动,因而只必要修改图片高度就可以
ImageView.contentMode=UIViewContentModeScaleAspectFill;

威尼斯娱乐手机版网站 11.gif

2、UILabel显示不一样颜色字体

NSMutableAttributedString和数组同样分成可变字符串和不可变字符串, NSAttributedString正是不可变字符串NSMutableAttributedString同理可得就是贰个带属性的字符串,由此它的选择相当轻易,

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:label.text];

[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange];

[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange];

[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange];

label.attributedText = string;

,247);mj�8dxݞ

3、计算UILabel上某段文字的frame

@implementation UILabel

- boundingRectForCharacterRange:range

{

NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:[self attributedText]];

NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];

[textStorage addLayoutManager:layoutManager];

NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:[self bounds].size];

textContainer.lineFragmentPadding = 0;

[layoutManager addTextContainer:textContainer];

NSRange glyphRange;

[layoutManager characterRangeForGlyphRange:range actualGlyphRange:&glyphRange];

return [layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:textContainer];

}

  • 1.开始化字符串
  • 2.初步化字符串所须求的习性
  • 3.将质量赋值给字符串起首化方法- (instancetype)initWithString:(NSString *)str;``- (instancetype)initWithString:(NSString *)str attributes:(nullable NSDictionary<NSString *, id> *)attrs;``- (instancetype)initWithAttributedString:(NSAttributedString *)attrStr;开首化属性
  • NSFontAttributeName 字体
  • NSForegroundColorAttributeName 字体颜色
  • NSBackgroundColorAttributeName 背景颜色
  • NSLigatureAttributeName 连字符该属性所对应的值是叁个 NSNumber 对象。连体字符是指有些连在一齐的字符,它们选用单个的图元符号。0 代表从没连体字符。1 代表使用默许的连体字符。2 表示使用全部连体符号。暗许值为 1(注意,iOS 不协助值为 2)。
  • NSParagraphStyleAttributeName 段落该属性所对应的值是叁个NSParagraphStyle 对象。该属性在一段文本上行使两天性情。假如不点名该属性,则默以为NSParagraphStyle 的defaultParagraphStyle 方法再次回到的暗中认可段落属性
  • NSKernAttributeName 字间隔该属性所对应的值是叁个 NSNumber 对象。字母紧排钦点了用来调度字距的像素点数。字母紧排的效能依赖于字体。值为 0 表示不应用假名紧排。暗中同意值为0
  • NSStrikethroughStyleAttributeName 删除线
  • NSUnderlineStyleAttributeName 下划线
  • NSStrokeColorAttributeName 边线颜色该属性所对应的值是一个 UIColor 对象。如若该属性不点名,则一模二样 NSForegroundColorAttributeName。不然,钦点为删除线或下划线颜色。更加多细节见“Drawing attributedstrings that are both filled and stroked”
  • NSStrokeWidthAttributeName 边线宽度
  • NSShadowAttributeName 阴影
  • NSVerticalGlyphFormAttributeName 横竖制版实例

4、相比较五个NSDate相差多少时辰

NSDate* date1 = someDate;

NSDate* date2 = someOtherDate;

NSTimeInterval distanceBetweenDates = [date1 timeIntervalSinceDate:date2];

double secondsInAnHour = 3600;

// 除以3600是把秒化成小时,除以60获得结果为离开的秒钟数

NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;

 // 设置颜色等 NSMutableDictionary *arrDic = [NSMutableDictionary dictionary]; arrDic[NSForegroundColorAttributeName] = [UIColor purpleColor]; arrDic[NSBackgroundColorAttributeName] = [UIColor greenColor]; arrDic[NSKernAttributeName] = @10; arrDic[NSUnderlineStyleAttributeName] = @1; NSMutableAttributedString *attriOneStr = [[NSMutableAttributedString alloc]initWithString:@"来呀,快活呀,反正有大把时光" attributes:arrDic]; self.oneLabel.attributedText = attriOneStr; // 简单的图文混排 NSMutableAttributedString *arrTwoStr = [[NSMutableAttributedString alloc]init]; NSMutableAttributedString *TwoChildStr = [[NSMutableAttributedString alloc]initWithString:@"你好啊"]; [arrTwoStr appendAttributedString:TwoChildStr]; NSTextAttachment *attachMent = [[NSTextAttachment alloc]init]; attachMent.image = [UIImage imageNamed:@"2"]; attachMent.bounds = CGRectMake(0, -5, 20, 20); NSAttributedString *picStr = [NSAttributedString attributedStringWithAttachment:attachMent]; [arrTwoStr appendAttributedString:picStr]; NSAttributedString *TwooStr = [[NSAttributedString alloc]initWithString:@"我是小菜鸟"]; [arrTwoStr appendAttributedString:TwooStr]; self.twoLabel.attributedText = arrTwoStr;

5、播放一张张延续的图形

本文由澳门威利斯人发布于网络资讯,转载请注明出处:威尼斯娱乐手机版网站:自己搜集的iOS开发经验

关键词: iOS开发笔 经验 IOS 入门 看我