精通iOS开发 第六版 page50
放在这里方便查询
</pre><pre name="code" class="objc">
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *Label;
@property (strong, nonatomic) IBOutlet UIView *Right;
@property (strong, nonatomic) IBOutlet UIView *Left;
- (IBAction)TouchUp:(id)sender;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)TouchUp:(id)sender {
NSString *title = [sender titleForState:UIControlStateNormal];
NSString *plainText = [NSString stringWithFormat:@"%@ button pressed", title];
// _Label.text = plainText;
NSMutableAttributedString *styleText = [[NSMutableAttributedString alloc] initWithString:plainText];
NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:_Label.font.pointSize]};
NSRange range = [plainText rangeOfString:title];
[styleText setAttributes:attributes range:range];
_Label.attributedText = styleText;
}
@end