基础控件相关使用

1.一个UILabel显示不同样式的字符串:

 UILabel *summaryLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 140, 100, 30)];
    self.summaryLabel = summaryLabel;

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String,try your best to test attributed string text"];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(0, 5)];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(6, 12)];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(19, 6)];

    UILabel *attrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 150, 320 - 40, 90)];
    attrLabel.attributedText = str;
    attrLabel.numberOfLines = 0;
    [self.view addSubview:attrLabel];

2.UILabel显示html文本:

 NSString * htmlString = @"<html><body> Some html string \n <font size=\"13\" color=\"red\">This is some text!</font> </body></html>";
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
UILabel * myLabel = [[UILabel alloc] initWithFrame:self.view.bounds];
myLabel.attributedText = attrStr;
[self.view addSubview:myLabel];

3.tableView有数据的有线,没数据的也有线,没数据时如何去掉线

self.tableView.tableFooterView = [[UIView alloc] init];

4.自定义UITextField使TextField文字有缩进效果

   很简单,继承UITextfield,覆盖父类如下两个方法!

            - (CGRect)textRectForBounds:(CGRect)bounds

          - (CGRect)editingRectForBounds:(CGRect)bounds

    代码如下:

#import <UIKit/UIKit.h>  
@interface WXTextField : UITextField  
@end

#import "WXTextField.h"  
@implementation WXTextField  
//控制文本所在的的位置,左右缩 10  
- (CGRect)textRectForBounds:(CGRect)bounds  
{  
    return CGRectInset(bounds, 30, 0);  
}  
  
//控制编辑文本时所在的位置,左右缩 10  
- (CGRect)editingRectForBounds:(CGRect)bounds  
{  
    return CGRectInset(bounds, 30, 0);  
}  
@end

5.隐藏状态栏

[[UIApplication sharedApplication] setStatusBarHidden:YES];

6.隐藏导航条

    [self.navigationController setNavigationBarHidden:false animated:true];






你可能感兴趣的:(基础控件相关使用)