设置textView或者label的行间距方法

一,效果图。

二,代码。

RootViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //UILabel
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 100, 200, 300)];
    label.backgroundColor=[UIColor orangeColor];
    [email protected]"公元前3000年,印度河流域的居民的数字使用就已经比较普遍,居民们采用了十进位制的计算法。到吠陀时代(公元前1500~公元前500年),雅利安人已意识到数字在生产活动和日常生活中的作用,创造了一些简单的、不完全的数字。公元前3世纪,印度出现了整套的数字,但各地的写法不一,其中最典型的是婆罗门式,它的独到之处就是从1~9每个数都有专用符号,现代数字就是从它们中脱胎而来的。当时,“0”还没有出现。到了笈多时代(300~500年)才有了“0”,叫“舜若”(shunya),表示方式是一个黑点“●”,后来衍变成“0”。这样,一套完整的数字便产生了。这项劳动创作也对世界文化做出了巨大的贡献。";
    label.numberOfLines=0;
    [self.view addSubview:label];

    //设置行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineSpacing = 50;

    NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle};
    label.attributedText = [[NSAttributedString alloc]initWithString:label.text attributes:attributes];

}
时间: 2024-08-09 09:22:37

设置textView或者label的行间距方法的相关文章

【代码笔记】设置textView或者label的行间距方法

一,效果图. 二,代码. RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //UILabel UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 100, 200, 300)]; label.backgroundColor=[UIColor oran

iOS开发之UITextView,设置textView的行间距及placeholder

一.设置textView的行间距 1.如果只是静态显示textView的内容为设置的行间距,执行如下代码: //    textview 改变字体的行间距     NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];     paragraphStyle.lineSpacing = 10;// 字体的行间距          NSDictionary *attributes = @{  

Android如何设置TextView的行间距、行高。

     Android系统中TextView默认行间距比较窄,不美观.     我们可以设置每行的行间距,可以通过属性android:lineSpacingExtra或android:lineSpacingMultiplier来做. 在你要设置的TextView中加入如下代码: 1.android:lineSpacingExtra 设置行间距,如"8dp". 2.android:lineSpacingMultiplier 设置行间距的倍数,如"1.5″.       示例:

【转】Android中设置TextView的颜色setTextColor

原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setTextColor,这个方法被重载了,可以传入两种参数. public void setTextColor(int color) { mTextColor = ColorStateList.valueOf(color); updateTextColors(); } public void setTextCo

android在代码中四种设置控件背景颜色的方法(包括RGB)

转载请注明出处: http://blog.csdn.net/fth826595345/article/details/9208771  TextView tText=(TextView) findViewById(R.id.textv_name); //第1种: tText.setTextColor(android.graphics.Color.RED);//系统自带的颜色类 // 第2种: tText.setTextColor(0xffff00ff);//0xffff00ff是int类型的数据

通过Spannable对象设置textview的样式

通过Spannable对象我们可以设置textview的各种样式,其功能十分强大.通过SpannableString和它的setSpan(Object what, int start, int end, int flags)便可以对textview设置想要的效果了,这里的what就是效果名,start和end是设置这个样式针对的是textview的字符位置. 1. 简单用法 创建一个spannableString,textview可以通过setText设置这个对象,效果就是textview显示了

Android中设置TextView的颜色setTextColor

tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColor(Color.rgb(255, 255, 255));  //注意Color是大写C,不是color.holo_orange_dark,这样错误并没效果的 tv.setBackgroundResource(R.drawable.icon_bg_rectang_stroke); 这种方法也就是传入int co

[转]Android中设置TextView的颜色setTextColor

[转自]http://txlong-onz.iteye.com/blog/1249609 Android中设置TextView的颜色setTextColor android中设置TextView的颜色有方法setTextColor,这个方法被重载了,可以传入两种参数. 1 public void setTextColor(int color) { 2 mTextColor = ColorStateList.valueOf(color); 3 updateTextColors(); 4 } 5 6

Android进阶(二十二)设置TextView文字水平垂直居中

设置TextView文字水平垂直居中 有2种方法可以设置TextView文字居中: 一:在xml文件设置:android:gravity="center" 二:在程序中设置:m_TxtTitle.setGravity(Gravity.CENTER); 备注:android:gravity和android:layout_gravity的区别在于前者对控件内部操作,后者是对整个控件操作. 例如:android:gravity="center"是对textView中文字居