UIlabel设置不同的颜色

NSString *string = @"注册过程中出现问题,致电400-650-5167联系会养车工作人员";
    NSRange range = [string rangeOfString: @"400-650-5167"];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString: string];
    [attribute addAttributes: @{NSForegroundColorAttributeName: [UIColor colorWithRed:84.0f/255.0f green:116.0f/255.0f blue:173.0f/255.0f alpha:1.0f]} range: range];
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0, 200, 320.0, 100.0)];
    [label setText: string];
    label.textColor = [UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1.0f];
    label.font = [UIFont boldSystemFontOfSize:14];
    label.numberOfLines = 0;
    [label setAttributedText: attribute];
    [self.view addSubview:label];

时间: 2024-08-27 06:25:46

UIlabel设置不同的颜色的相关文章

iOS:UILabel设置不同字体颜色

NSString *str = @"0123456789";//label内容 NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:str]; //根据下标索引设置字体颜色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];

关于UILabel设置AttributedString以后末尾...不出现的问题

UILabel我们都知道在内容盛不下的时候末尾就会显示... 但是当你给UILabel设置AttributedString的时候就会发现,虽然内容盛不下,但是最后的...也是没有的 这可能是AttributedString设置以后UILabel原本的设置就不生效了(包括字体,字体颜色等属性) 如果你想要显示...如要手动再给UILabel设置截断模式 NSMutableAttributedString *string = [[NSMutableAttributedString alloc] in

106设置滚动条的颜色(扩展知识:将滚动条设置为分页的形式)

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end ViewController.m 1 #import "ViewController.h" 2 #import "KMLabelViewController.h" 3 4 @interface ViewController () 5 - (void

TPanel的默认颜色存储在dfm中,读取后在Paint函数中设置刷子的颜色,然后填充整个背景

声明如下: TCustomPanel = class(TCustomControl) private FFullRepaint: Boolean; FParentBackgroundSet: Boolean; procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED; protected procedure CreateParams(var Params: TCreateParams); override;

【转】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

UILabel设置行间距和字间距并计算高度-b

#define UILABEL_LINE_SPACE 6 #define HEIGHT [ [ UIScreen mainScreen ] bounds ].size.height //给UILabel设置行间距和字间距 -(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font { NSMutableParagraphStyle *paraStyle = [[NSMutablePara

设置statusBar状态栏颜色

设置statusBar的[前景部分] 简单来说,就是设置显示电池电量.时间.网络部分标示的颜色, 这里只能设置两种颜色: 默认的黑色(UIStatusBarStyleDefault) 白色(UIStatusBarStyleLightContent) 可以设置的地方有两个:plist设置里面 和 程序代码里 1.plist设置statusBar 在plist里增加一行 UIStatusBarStyle(或者是“Status bar style”也可以),这里可以设置两个值,就是上面提到那两个 UI

Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet())

在Qt中设置widget背景颜色或者图片方法很多种:重写paintEvent() , 调色板QPalette , 样式表setStyleSheet等等. 但是各种方法都有其注意事项,如果不注意则很容易陷入麻烦中. 1:setStyleSheet() 这个函数我一直很喜欢使用,因为只要写一句就可以实现效果,比其他方法都简单,但是其却有一个很值得注意的地方,也就是这个地方让我大吃苦头. 亦即:①:该函数只能用于设置有父窗口的子窗口的背景!如果一个窗口没有子窗口,则无法使用该函数来设置背景颜色或图  

JavaGUI——设置框架背景颜色和按钮颜色

import java.awt.Color; import javax.swing.*; public class MyDraw { public static void main(String[] args) { //创建框架 JFrame myFrame=new JFrame("图画"); //myFrame.setLocation(200, 300);//第1参数表示离左屏幕边框距离,第2参数表示离屏幕上边框距离 myFrame.setSize(600, 400); myFram