@@ -15,30 +15,38 @@ - (id)initWithFrame:(CGRect)frame activities:(NSArray *)activities
1515{
1616 self = [super initWithFrame: frame];
1717 if (self) {
18+ self.clipsToBounds = YES ;
1819 _activities = activities;
19- _backgroundImageView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , frame.size.height - 417 , frame.size.width, 417 )];
20- _backgroundImageView.image = [UIImage imageNamed: @" Background" ];
21- _backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
22- [self addSubview: _backgroundImageView];
2320
24- _scrollView = [[UIScrollView alloc ] initWithFrame: CGRectMake (0 , 39 , frame.size.width, 300 )];
21+ if (UI_USER_INTERFACE_IDIOM () == UIUserInterfaceIdiomPhone) {
22+ _backgroundImageView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , frame.size.width, 417 )];
23+ _backgroundImageView.image = [UIImage imageNamed: @" Background" ];
24+ _backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
25+ [self addSubview: _backgroundImageView];
26+ }
27+
28+
29+ _scrollView = [[UIScrollView alloc ] initWithFrame: CGRectMake (0 , 39 , frame.size.width, self .frame.size.height - 104 )];
2530 _scrollView.showsHorizontalScrollIndicator = NO ;
2631 _scrollView.showsVerticalScrollIndicator = NO ;
2732 _scrollView.delegate = self;
28- // _scrollView.backgroundColor = [UIColor blackColor];
33+ _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
34+ // _scrollView.backgroundColor = [UIColor blueColor];
2935 [self addSubview: _scrollView];
3036
3137 NSInteger index = 0 ;
3238 NSInteger row = -1 ;
3339 NSInteger page = -1 ;
3440 for (REActivity *activity in _activities) {
35- NSInteger col = index%3 ;
41+ NSInteger col;
42+
43+ col = index%3 ;
3644 if (index % 3 == 0 ) row++;
3745 if (index % 9 == 0 ) {
3846 row = 0 ;
3947 page++;
4048 }
41- NSLog (@" index = %i " , index % 9 );
49+ // NSLog(@"index = %i", index % 9);
4250 UIView *view = [self viewForActivity: activity
4351 index: index
4452 x: (20 + col*80 + col*20 ) + page * frame.size.width
@@ -49,24 +57,25 @@ - (id)initWithFrame:(CGRect)frame activities:(NSArray *)activities
4957 _scrollView.contentSize = CGSizeMake ((page +1 ) * frame.size .width , _scrollView.frame .size .height );
5058 _scrollView.pagingEnabled = YES ;
5159
52- _pageControl = [[UIPageControl alloc ] initWithFrame: CGRectMake (0 , 327 , frame.size.width, 10 )];
60+ _pageControl = [[UIPageControl alloc ] initWithFrame: CGRectMake (0 , frame.size.height - ( UIInterfaceOrientationIsPortrait ([UIDevice currentDevice ].orientation) ? 90 : 86 ) , frame.size.width, 10 )];
5361 _pageControl.numberOfPages = page + 1 ;
5462 [_pageControl addTarget: self action: @selector (pageControlValueChanged: ) forControlEvents: UIControlEventValueChanged];
5563 [self addSubview: _pageControl];
5664
5765 if (_pageControl.numberOfPages <= 1 )
5866 _pageControl.hidden = YES ;
5967
60- UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
61- [button setBackgroundImage: [[UIImage imageNamed: @" Button" ] stretchableImageWithLeftCapWidth: 22 topCapHeight: 47 ] forState: UIControlStateNormal];
62- button.frame = CGRectMake (22 , 352 , 276 , 47 );
63- [button setTitle: @" Cancel" forState: UIControlStateNormal];
64- [button setTitleColor: [UIColor whiteColor ] forState: UIControlStateNormal];
65- [button setTitleShadowColor: [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 0.4 ] forState: UIControlStateNormal];
66- [button.titleLabel setShadowOffset: CGSizeMake (0 , -1 )];
67- [button.titleLabel setFont: [UIFont boldSystemFontOfSize: 19 ]];
68- [button addTarget: self action: @selector (cancelButtonPressed ) forControlEvents: UIControlEventTouchUpInside];
69- [self addSubview: button];
68+ _cancelButton = [UIButton buttonWithType: UIButtonTypeCustom];
69+ [_cancelButton setBackgroundImage: [[UIImage imageNamed: @" Button" ] stretchableImageWithLeftCapWidth: 22 topCapHeight: 47 ] forState: UIControlStateNormal];
70+ _cancelButton.frame = CGRectMake (22 , 352 , 276 , 47 );
71+ [_cancelButton setTitle: @" Cancel" forState: UIControlStateNormal];
72+ [_cancelButton setTitleColor: [UIColor whiteColor ] forState: UIControlStateNormal];
73+ [_cancelButton setTitleShadowColor: [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 0.4 ] forState: UIControlStateNormal];
74+ [_cancelButton.titleLabel setShadowOffset: CGSizeMake (0 , -1 )];
75+ [_cancelButton.titleLabel setFont: [UIFont boldSystemFontOfSize: 19 ]];
76+ [_cancelButton addTarget: self action: @selector (cancelButtonPressed ) forControlEvents: UIControlEventTouchUpInside];
77+ // _cancelButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
78+ [self addSubview: _cancelButton];
7079 }
7180 return self;
7281}
@@ -101,6 +110,18 @@ - (UIView *)viewForActivity:(REActivity *)activity index:(NSInteger)index x:(NSI
101110 return view;
102111}
103112
113+ - (void )layoutSubviews
114+ {
115+ [super layoutSubviews ];
116+
117+ CGRect frame = _cancelButton.frame ;
118+ frame.origin .y = self.frame .size .height - 47 - 16 ;
119+ frame.origin .x = (self.frame .size .width - frame.size .width ) / 2 .0f ;
120+ _cancelButton.frame = frame;
121+
122+ // _scrollView.frame = CGRectMake(_scrollView.frame.origin.x, _scrollView.frame.origin.y, _scrollView.frame.size.width, self.frame.size.height - 104);
123+ }
124+
104125#pragma mark -
105126#pragma mark Button action
106127
0 commit comments