【程式碼筆記】iOS-替換電話號碼中間4位為-號
阿新 • • 發佈:2019-01-28
一,效果圖。
二,程式碼。
RootViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//電話號碼
UILabel *telLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 20)];
telLabel.textColor = [UIColor grayColor];
telLabel.text = @"13793333281";
//字串的擷取
NSString *string = [telLabel.text substringWithRange:NSMakeRange(4,4)];
//字串的替換
telLabel.text = [telLabel.text stringByReplacingOccurrencesOfString:string withString:@"----"];
[self.view addSubview:telLabel];
}