Reputation: 843
I created a subclass MyCalender
of UIView
and take UIScrollView
in MyCalender
class. And Use this MyCalender
as subview of any other viewController. But the problem is that UIScrollView
is not scrolling. I am using Xcode 5
MyCalender.h file
#import <UIKit/UIKit.h>
@interface MyCalender : UIView
{
UIScrollView *scrollMonth;
}
@property(strong,nonatomic) UIScrollView *scrollMonth;
@end
MyCalender.M file ------
#import "MyCalender.h"
@implementation MyCalender
@synthesize scrollMonth;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
scrollMonth =[[UIScrollView alloc] init];
[scrollMonth setFrame:CGRectMake(0, 66, 320, 220)];
[scrollMonth setContentSize:CGSizeMake(320, 500)];
[scrollMonth setBackgroundColor:[UIColor blackColor]];
[scrollMonth setUserInteractionEnabled:YES];
[self addSubview:scrollMonth];
//----------- ---------- -------- ---------
}
return self;
}
TestView class in which I used MyCalender class
#import <UIKit/UIKit.h>
#import "MyCalender.h"
@interface testView : UIViewController
{
MyCalender *viewCALENDER;
}
@property(strong,nonatomic) MyCalender *viewCALENDER;
@end
Testview.m
#import "testView.h"
@interface testView ()
@end
@implementation testView
@synthesize viewCALENDER;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
viewCALENDER=[[MyCalender alloc] initWithFrame:CGRectMake(0, 64, 320, 64)];
[self.view addSubview:viewCALENDER];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Upvotes: 0
Views: 117
Reputation: 5454
from the looks of it, your scrollview is not visible in viewCALENDAR
:
viewCALENDER=[[MyCalender alloc] initWithFrame:CGRectMake(0, 64, 320, 64)];
[scrollMonth setFrame:CGRectMake(0, 66, 320, 220)];
The container view (viewCALENDAR
) has a 64px height, while your scrollview isplaced at y position 66.
To clarify on 'not visible' - the scroll view may be visible if clipsToBounds==NO
for the container view, but in this case it will not be interactive.
Upvotes: 3