myboard中
纯代码
- (void)viewDidLoad {
//1.1 创建按钮对象,按钮类型只能初始化时设置
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//1.2 设置位置和大小
button.frame = CGRectMake(100, 200, 200, 150);
//1.3 设置背景颜色
button.backgroundColor = [UIColor orangeColor];
//1.4 设置文字
[button setTitle:@"普通状态" forState:UIControlStateNormal];
[button setTitle:@"高亮状态" forState:UIControlStateHighlighted];
//1.5 设置文字颜色
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//1.6 设置文字阴影
[button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateHighlighted];
button.titleLabel.shadowOffset = CGSizeMake(3, 2);
//1.7 插入图片
[button setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
//[button setBackgroundImage:[UIImage imageNamed:<#(nonnull NSString *)#>] forState:<#(UIControlState)#>];
//2.0 添加到View中
[self.view addSubview:button];
//3.0 设置监听
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)click:(UIButton *)button{
button.enabled = NO;
}
UIScrollerView
// 设置scrollerView的属性
scrollerView.contentSize = imageView.image.size;
------------
UIScrollView *scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(100, 100, 220, 500)];
[self.view addSubview:scrollerView];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]];
[scrollerView addSubview:imageView];
// 设置scrollerView的属性
scrollerView.contentSize = imageView.image.size;
// 设置弹簧效果 默认有
//scrollerView.bounces = NO;
/*
UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
indicatorView.center = CGPointMake(100, -50);
[indicatorView startAnimating];
[scrollerView addSubview:indicatorView];
// 下拉刷新用到
scrollerView.alwaysBounceVertical = YES;
scrollerView.alwaysBounceHorizontal = YES;
*/
// 默认位置偏移量
scrollerView.contentOffset = CGPointMake(100, 20);
移动到右下角:
- (IBAction)rightBottom {
[UIView animateWithDuration:2.0 animations:^{
CGFloat offsetX = self.scrollerView.contentSize.width - self.scrollerView.frame.size.width;
CGFloat offsetY = self.scrollerView.contentSize.height -self.scrollerView.frame.size.height;
CGPoint offset = CGPointMake(offsetX, offsetY);
[self.scrollerView setContentOffset:offset];
}];
//[self.scrollerView setContentOffset:offset animated:YES];
}