3

我想根据我的需要设置 iCarousel 的框架。首先它显示在模拟器的中间,但我尝试了我的代码,现在它显示在模拟器的顶部。

我正在尝试这段代码:

// Try to add custom view for setting height and width of iCarousel

UIView *Carasouel_Customview = [[UIView alloc]initWithFrame:CGRectMake(10, -245, 768, 245)];
[self.view addSubview:Carasouel_Customview];


// Initialize and configure the carousel

//carousel = [[iCarousel alloc] initWithFrame:self.view.bounds];
carousel = [[iCarousel alloc] initWithFrame:Carasouel_Customview.bounds];
//carousel = [[iCarousel alloc] initWithFrame:CGRectMake(20, 200, 179, 245)];
carousel.autoresizingMask = UIViewAutoresizingFlexibleWidth |    UIViewAutoresizingFlexibleHeight;
carousel.type = iCarouselTypeRotary;
carousel.dataSource = self;
carousel.delegate = self;
[self.view addSubview:carousel];

专家的任何提示都将非常受欢迎。

4

2 回答 2

3
self.carousel = [[iCarousel alloc]initWithFrame:CGRectMake(0.0, 0.0, 200.0, 150.0)];
self.carousel.delegate = self;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeLinear;

self.carousel.clipsToBounds = YES; //This is main point

[self.view addSubview:self.carousel];

当我们将 customFrame 设置为iCarousel时,我们得到它的全屏宽度。所以只需设置它的clipsToBounds属性YES:)

于 2013-03-07T07:53:27.907 回答
1

您将 y 坐标设置-245Carasouel_Customview,然后设置carousel.frame-Carasouel_Customview.bounds这里 y 坐标为 0。

您正在添加carouselself.view而不是Carasouel_Customview- 那么您期望什么?

解决方案:添加carousel为子视图Carasouel_Customviewcarousel.frame使用自定义值设置。

于 2013-01-03T09:47:45.263 回答