2011-04-21 76 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