
Create a view (XIB) with this shared layout, as shown in the image above. There is UILabel, UITextView and UIView (the blue rectangle is a UIView with a set of background colors). Let me call it ThreadView.xib. Include the shortcut, text view, and view as presentation properties.
Then we can create a way to generate one of these views for use and a method to add more ThreadView threads as subtasks based on how many comments / replies the message has.
+ (instancetype)threadViewWithLabelText:(NSString *)labelText textViewText:(NSString *)textViewText color:(UIColor *)color { ThreadView *threadView = [[[NSBundle mainBundle] loadNibNamed:@"ThreadView" owner:self options:nil] firstObject]; if (threadView) { threadView.label.text = labelText; threadView.textView.text = textViewText; threadView.colorView.backgroundColor = color; } return threadView; } - (void)addCommentView:(ThreadView *)threadView toViewController:(UIViewController *)viewController { threadView.frame = CGRectMake(self.frame.origin.x + 25, self.textView.frame.origin.y + self.textView.frame.size.height, self.frame.size.width - (self.frame.origin.x + 10), self.frame.size.height - (self.textView.frame.origin.y + self.textView.frame.size.height)); [viewController.view addSubview:threadView]; }
Now, in the main view controller, we can create and add these views only with these two method calls:
- (void)viewDidLoad { [super viewDidLoad]; // Load the first post ThreadView *originalPost = [ThreadView threadViewWithLabelText:@"10 Some Words 2014 More Words" textViewText:loremIpsum color:[UIColor blueColor]]; originalPost.frame = CGRectMake(self.view.frame.origin.x + 8, self.view.frame.origin.y + 15, self.view.frame.size.width - 8, self.view.frame.size.height - 15); [self.view addSubview:originalPost]; // Load a comment post ThreadView *commentPost = [ThreadView threadViewWithLabelText:@"12 December 2014 Maybe A Username" textViewText:loremIpsum color:[UIColor greenColor]]; [originalPost addCommentView:commentPost toViewController:self]; }
This will give us the result, as in the figure below. This code may use some refactoring / restructuring, but this should get you started. You can also mix use of autorun and / or set viewing frames.

keithbhunter
source share