#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIScrollViewDelegate> @property(strong,nonatomic) UIScrollView* scrollview; @property(strong,nonatomic) UIView* view11; @property(strong,nonatomic) UIView* view22; @property(strong,nonatomic) UIPageControl* pageControl; @end
在viewDidLoad中:
scrollview = [[UIScrollView alloc] init]; scrollview.frame = CGRectMake(10, 0, 300, 108); scrollview.contentSize = CGSizeMake(600, 108); scrollview.showsVerticalScrollIndicator = NO; scrollview.showsHorizontalScrollIndicator = NO; //myScrollView.clipsToBounds = YES; scrollview.delegate = self; scrollview.scrollEnabled = YES; scrollview.pagingEnabled = YES; scrollview.bounces = NO; view11 = [[UIView alloc] init]; //将图层的边框设置为圆脚 view11.layer.cornerRadius = 10; view11.layer.masksToBounds = YES; //给图层添加一个有色边框 view11.layer.borderWidth = 1; //view1.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor]; view11.layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]; view11.frame = CGRectMake(300, 0, 300, 108); view11.backgroundColor = [UIColor blackColor]; [scrollview addSubview:view11]; view22 = [[UIView alloc] init]; //将图层的边框设置为圆脚 view22.layer.cornerRadius = 10; view22.layer.masksToBounds = YES; //给图层添加一个有色边框 view22.layer.borderWidth = 1; //view1.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor]; view22.layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]; view22.frame = CGRectMake(0, 0, 300, 108); view22.backgroundColor = [UIColor colorWithRed:0.31 green:0.31 blue:0.31 alpha:1]; [scrollview addSubview:view22]; pageControl = [[UIPageControl alloc] init]; pageControl.frame = CGRectMake(150, 100, 20, 20); pageControl.numberOfPages = 2; pageControl.currentPage = 0; [pageControl addTarget:self action:@selector(changePage:)forControlEvents:UIControlEventValueChanged]; [self.view addSubview:scrollview]; [self.view addSubview:pageControl];
UIPageController
最新推荐文章于 2022-02-09 20:50:35 发布