2011-04-21 68 views
0

我尝试添加图片到我的观点是,在UIScrollView无法添加UIImageView?

这里是我的.h

@interface NormalDetail : UIViewController <UIScrollViewDelegate> { 
    IBOutlet UIImageView *lineImg; 
} 

@property (nonatomic, retain) UIImageView *lineImg; 

@end 

这里是我的.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    //Set ScrollView 
    scrollView.contentSize = CGSizeMake(320.0f, 1800.0f); 
    //End Set ScrollView 
    [self setupTextView]; 
} 


- (void) setupTextView 
{ 
    textDescription.scrollEnabled = NO; 
    NSString *foo = @"Hello Test"; 
    textDescription.text = foo; 
    /*Here is something for dynamic textview*/ 
    CGRect frame; 
    frame = textDescription.frame; 
    frame.size.height = [textDescription contentSize].height; 
    textDescription.frame = frame; 
    /**/ 

    int linePosition = frame.size.height+20; 
    lineImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"line.png"]]; 
    CGRect line2Frame = CGRectMake(-8, 600, 328, 10); 
    lineImg.frame = line2Frame; 
} 

这有什么错我的代码,我的图片没有出现。请帮助我。(

回答

2

您将需要对的UIImageView到scorllView

- (void) setupTextView 
{ 
    textDescription.scrollEnabled = NO; 
    NSString *foo = @"Hello Test"; 
    textDescription.text = foo; 
    /*Here is something for dynamic textview*/ 
    CGRect frame; 
    frame = textDescription.frame; 
    frame.size.height = [textDescription contentSize].height; 
    textDescription.frame = frame; 
    /**/ 

    int linePosition = frame.size.height+20; 
    lineImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"line.png"]]; 
    CGRect line2Frame = CGRectMake(-8, 600, 328, 10); 
    lineImg.frame = line2Frame; 

    //Add the image view as a subview to yout scrollview. 
    [scrollView addSubView:lineImg]; 
} 
+0

哇THX我明白了:) – crazyoxygen 2011-04-21 07:52:21

+1

,还可以使用'IBOutlet'只有当你已经添加在厦门国际银行的对象。 当您使用'IBOutlet'时,将其用作 'IBOutlet Class * ObjectName;' 用于声明。 并创建属性为 '@property(nonatomic,retain)IBOutlet Class * ObjectName;' 并且不要忘记将对象与xib绑定。 – 2011-04-21 07:57:28

+0

我完全同意@Himanshu。 +1 – rckoenes 2011-04-21 08:00:29