I am creating a customview which is a subclass of UIScrollView. I am adding UIButtons inside UIScrollView dynamically along with images and actions. But scrollview is not scrolling horizontally with buttons. I know this topic is discussed many times on SO. I tried all posts posted on SO, but not getting expected result. Any suggestion about where i am going wrong will be helpful.
MyCustomView.h
@interface MyCustomView : UIScrollView
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
+ (id)customView;
@end
MyCustomView.m
@implementation MyCustomView
@synthesize scrollView;
+ (id)customView
{
    MyCustomView *customView = [[[NSBundle mainBundle]  loadNibNamed:@"MyCustomView" owner:nil options:nil] lastObject];
    if ([customView isKindOfClass:[MyCustomView class]])
        return customView;
    else
        return nil;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}
- (void)drawRect:(CGRect)rect
{
    [self setupHorizontalScrollView];
}
- (void)setupHorizontalScrollView
{
    //scrollView.delegate = self;
    [self.scrollView setBackgroundColor:[UIColor blueColor]];
    [scrollView setCanCancelContentTouches:YES];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView.clipsToBounds = NO;
    scrollView.scrollEnabled = YES;
    //scrollView.pagingEnabled = YES;
    CGFloat cx = 0;
    NSArray *buttons = @[@{@"Tag":@1,@"Image":[UIImage imageNamed:@"borderImage1.png"]},
                         @{@"Tag":@2,@"Image":[UIImage imageNamed:@"borderImage2.png"]},
                         @{@"Tag":@3,@"Image":[UIImage imageNamed:@"borderImage3.png"]},
                         @{@"Tag":@4,@"Image":[UIImage imageNamed:@"borderImage4.png"]},
                         @{@"Tag":@1,@"Image":[UIImage imageNamed:@"borderImage1.png"]},
                         @{@"Tag":@2,@"Image":[UIImage imageNamed:@"borderImage2.png"]},
                         @{@"Tag":@3,@"Image":[UIImage imageNamed:@"borderImage3.png"]},
                         @{@"Tag":@4,@"Image":[UIImage imageNamed:@"borderImage4.png"]},
                         @{@"Tag":@1,@"Image":[UIImage imageNamed:@"borderImage1.png"]}
                         ];
    // CGRect frame = CGRectMake(0.0f, 0.0f, 50.0f, 30.0f);
    for (NSDictionary *dict in buttons)
    {
        UIButton *button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
        CGRect rect = button.frame;
        rect.size.height = 40;
        rect.size.width = 40;
        rect.origin.x = cx;
        rect.origin.y = 0;
        button.frame = rect;
        button.tag = [dict[@"Tag"] integerValue];
        [button setImage:dict[@"Image"]
                forState:UIControlStateNormal];
      //  [button addTarget:self action:@selector(buttonAction:)
      //   forControlEvents:UIControlEventTouchUpInside];
        [self.scrollView addSubview:button];
        //frame.origin.x+=frame.size.width+20.0f;
        cx += button.frame.size.width+5;
    }
    [scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}
@end      
I went through below SO links, but didn't get solution.
 
     
     
     
    