答案 0 :(得分:1)
是的,你可以。
您必须像往常一样创建UITextView
,并将图片作为子视图添加到UIImageView
中。
yourTextView = [[UITextView alloc] init];
yourTextView.frame = CGRectMake(0, 10, self.view.frame.size.width, self.view.frame.size.height);
yourTextView.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:20];
yourTextView.text = @"The year was 1572. Pratap Singh had just become the Maharana of Mewar and he had not been back in Chittor since 1567. His old fort and his home beckoned to him. The pain of his father's death, and the fact that his father had not been able to see Chittor again, troubled the young Maharana deeply. But he was not the only one troubled at this time. Akbar had control of Chittor but not the kingdom of Mewar. So long as the people of Mewar swore by their Maharana, Akbar could not realize his ambition of being the Jahanpanah of Hindustan.";
[self.view addSubview:yourTextView];
yourImageView = [[UIImageView alloc] init];
yourImageView.frame = CGRectMake(100, 100, self.view.frame.size.width-100, (self.view.frame.size.width-100)*1.5 );
yourImageView.image = [UIImage imageNamed:@"imageOfAnOldSamurai.png"];
[yourTextView addSubview:yourImageView];
要使textview中的文本环绕图像,请使用exclusionPaths
UIBezierPath
与imageview中的帧。
- (void)viewDidLayoutSubviews {
UIBezierPath * exclusionPath = [UIBezierPath bezierPathWithRect:yourImageView.frame];
yourTextView.textContainer.exclusionPaths = @[exclusionPath];
}