【XCode - OC】之UI基础3

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];

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值