ios - 向 UIView 添加多个 subview

标签 ios objective-c iphone uiview charts

我正在使用一个名为 TWRCharts 的 iOS 图表软件,我正在尝试在同一个 View Controller 中添加多个图表。我使用 Interface Builder 添加了 UIView,并使用 .h 文件中的 socket 连接它们。当我尝试显示一张图表(我的主图表)时,它显示得很好。但是当我尝试添加更多图表时,它们没有出现。我试过颠倒图表绘制的顺序,在这种情况下出现了一个较小的图表,但没有别的。当我尝试将多个 subview 添加到它们各自的 View 时,什么也没有出现。这是我的 .h 和 .m 文件。

.h

#import <UIKit/UIKit.h>
#import "TWRChart.h"

@interface OverviewViewController : UIViewController

- (IBAction)didTapButton:(id)sender;

@property (strong, nonatomic) IBOutlet UIView *mainCircularChartUIView;
@property (strong, nonatomic) TWRChartView *mainCircularChart;

@property (strong, nonatomic) IBOutlet UIView *tapTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *tapTestCircularChart;

@property (strong, nonatomic) IBOutlet UIView *cogTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *cogTestCircularChart;

@property (strong, nonatomic) IBOutlet UIView *voiceTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *voiceTestCircularChart;

@property (strong, nonatomic) IBOutlet UIView *mentalHealthTestControllerUIView;
@property (strong, nonatomic) TWRChartView *mentalHealthTestController;

@end

.m(目前注释掉添加多个 subview )

- (void)viewDidLoad {
[super viewDidLoad];

/////////// Main Circular Chart View ////////////////////////
self.mainCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 60, 300, 300)];
self.mainCircularChart.backgroundColor = [UIColor clearColor];
self.mainCircularChart.userInteractionEnabled = YES;

// Add the chart view to the controller's view
[self.mainCircularChartUIView addSubview:self.mainCircularChart];

/////////// Sub Circular Chart Views ////////////////////////
self.tapTestCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
self.tapTestCircularChart.backgroundColor = [UIColor clearColor];
self.tapTestCircularChart.userInteractionEnabled = YES;

self.cogTestCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
self.cogTestCircularChart.backgroundColor = [UIColor clearColor];
self.cogTestCircularChart.userInteractionEnabled = YES;

// Add the chart view to the controller's view
//    [self.tapTestCircularChartUIView addSubview:self.tapTestCircularChart];
//    [self.cogTestCircularChartUIView addSubview:self.cogTestCircularChart];

[self loadMainCircularChart];
[self loadSubCircularCharts];
}

- (void)loadSubCircularCharts {
// Values
NSArray *values = @[@20, @30, @15, @5];

// Colors
UIColor *color1 = [UIColor colorWithHue:0.5 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color2 = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color3 = [UIColor colorWithHue:0.7 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color4 = [UIColor colorWithHue:0.8 saturation:0.6 brightness:0.6 alpha:1.0];
NSArray *colors = @[color1, color2, color3, color4];


// Tap Test Chart ///////////////////////////////////////////
TWRCircularChart *tapTestChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];

[self.tapTestCircularChart loadCircularChart:tapTestChart];

// Cog Test Chart ///////////////////////////////////////////
TWRCircularChart *cogTestChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
//
[self.tapTestCircularChart loadCircularChart:cogTestChart];

}

- (void)loadMainCircularChart {
// Values
NSArray *values = @[@20, @30, @15, @5];

// Colors
UIColor *color1 = [UIColor colorWithHue:0.5 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color2 = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color3 = [UIColor colorWithHue:0.7 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color4 = [UIColor colorWithHue:0.8 saturation:0.6 brightness:0.6 alpha:1.0];
NSArray *colors = @[color1, color2, color3, color4];

// Doughnut Chart
TWRCircularChart *pieChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];

[self.mainCircularChart loadCircularChart:pieChart];

}

最佳答案

你可以有两种实现方式

  1. 使用 ScrollView

如果你在使用 ScrollView 时遇到问题,那么

  1. 您可以通过在其中使用自定义单元格来使用 UITableView 来实现它。

关于ios - 向 UIView 添加多个 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41837581/

相关文章:

ios - 有限数量的 iOS 设备收到的推送通知

iphone - 将 GMT NSDate 转换为设备的当前时区

iPhone - fopen 和 pathForResource - 权限被拒绝

ios - 确定应用程序存储空间要求

ios - 如何使用 react 导航触发状态更新?

ios - Twitter 怎么知道 TWRequest 的来源?

ios - 核心数据一对多关系 : unrecognized selector sent to instance

ios - UIDatePicker返回当前日期,即使我选择其他日期也是如此

ios - xCode 6.3.1 在模拟器上运行时缺少引用

iphone - 可以在整个iphone中搜索pdf文件吗?