OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 UIScrollView 中添加多个 UIView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:37
标题: ios - 如何在 UIScrollView 中添加多个 UIView

我有一个绘制饼图的 UIView,我想以编程方式在 UIScrollView 中放置 3 个或 4 个图表。我该怎么做?

我的h文件是这样的

@class PieChart;

@interface ViewController : UIViewController {

}

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

和m文件

- (void)viewDidLoad
{
    [super viewDidLoad];


[scrollView setBackgroundColor:[UIColor blackColor]];
    [scrollView setCanCancelContentTouches:NO];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView.clipsToBounds = YES;     
    scrollView.scrollEnabled = YES;
    scrollView.pagingEnabled = YES;


         PieChart *chart = [[PieChart alloc]initWithFrame:CGRectZero];
        [chart setFrame:CGRectMake(100, 100, 200, 200)];

    [scrollView addSubview:chart];

}



Best Answer-推荐答案


如果需要给 View 添加 subview ,需要使用[view addSubview:subview]。这是常见的做法。 阅读框架和边界( View 和 subview 的坐标系):

据我了解,由于 ScrollView 的内容大小,您遇到了问题。在这里阅读更多:

希望对你有帮助。

关于ios - 如何在 UIScrollView 中添加多个 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11830536/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4