IOS UIScrollView 翻页,并且露出左边视图和右边视图的边缘效果。

本文介绍如何使用UIScrollView实现翻页效果,并展示如何通过裁剪背景视图使其边缘显露出来,增强用户体验。主要通过设置UIScrollView及其背景视图的属性来达到这一目的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



让UIScrollView 翻页,并且露出左边和右边的边缘效果。

具体的思路是让UIScrollView添加到一个背景视图scrollBg中,scrollBg裁剪到边缘,UIScrollView不裁剪到边缘。


- (void)loadView {
	[super loadView];
	self.title = @"主界面";
	self.view.backgroundColor = [UIColor grayColor];
    
    UIView * scrollBg = [[[UIView alloc] initWithFrame:CGRectMake(20, 10, 290, 400)] autorelease];
    scrollBg.backgroundColor = [UIColor redColor];
    scrollBg.clipsToBounds = YES;   //此句话重要,裁剪到边缘
    [self.view addSubview:scrollBg];

    UIScrollView * _activityPlaceScl = [[[UIScrollView alloc]initWithFrame:CGRectMake(25, 10, 240, 320)] autorelease];
    _activityPlaceScl.pagingEnabled = YES;
    _activityPlaceScl.backgroundColor = [UIColor clearColor];
    _activityPlaceScl.clipsToBounds = NO;      //此句话重要,不裁剪到边缘
    _activityPlaceScl.contentSize = CGSizeMake(_activityPlaceScl.frame.size.width * 5, _activityPlaceScl.frame.size.height);
    _activityPlaceScl.showsHorizontalScrollIndicator = NO;
    _activityPlaceScl.showsVerticalScrollIndicator = NO;
    [scrollBg addSubview:_activityPlaceScl];
    
    for (int page = 0; page < 5; page++) {
        CGRect frame = _activityPlaceScl.frame;
        UIButton *backgroundButton =  [UIButton buttonWithType:UIButtonTypeRoundedRect];
        backgroundButton.frame = CGRectMake(frame.size.width * page + 10, 0, 220, 258);
        [_activityPlaceScl addSubview:backgroundButton];
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值