以编程方式添加uiscrollview



我正试图在以下代码中添加一个UIScrollView,但有点不确定,因为它包含来自txt文件的内容。非常感谢在这方面的帮助。谢谢:)

#import "AboutController.h"

@implementation AboutController
- (NSString *)textForView 
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"txt"];
    NSError *error;
    return [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self showLogoInNavBar:YES];
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end

在您的:中

- (void)loadView
{
     CGRect scrollViewFrame = CGRectMake(0, 0, 320, 460);
     UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
     [self.view addSubview:scrollView];
     CGSize scrollViewContentSize = CGSizeMake(640, 460);
     [scrollView setContentSize:scrollViewContentSize];
}

希望有帮助!!

最新更新