2017-02-01 14 views
2

サードパーティ製のコントロールを1つ使用していますiCarouselビューで素敵なアニメーションが表示されます。ストーリーボードまたはxibからiCarouselビューを読み込む方法は?

すべてのものが正常に動作していると私はかなりこの制御について承知しています。

しかし、今まで、私はiCarouselビューにビューを追加し、画面上に表示するために、手動でコードを使用していますが、今、私の新しい要件ごとに私は以下の私はiCarouselビューを表示する必要がある4つの新しいテーマに3を持っているが、私の質問ですそのビューに関連しています。

  1. XIBから別のビューを読み込むにはどうすればよいですか?

  2. StoryboardからiCarouselのビューをロードするにはどうすればよいですか?

現在、以下の方法で手動でビューを追加しています。

viewForItemAtIndex:(NSInteger)index resuingView:(UIView*) view 

Storyboard/ XIBでこれを達成するのを手伝ってください。

+0

にいますあなたが必要とするソリューションの種類? – KKRocks

+0

詳細についてはこちらをご覧ください:1.別のビューをXIBからロードできますか? 2. iCarousel VIEWにストーリーボードを表示する方法はありますか? – KKRocks

+0

storyboardまたはxibからicarouselビューでカスタムビューを追加する必要があります。 – BhaviDev

答えて

3

iCarouselデータソース

func numberOfItems(in carousel: iCarousel) -> Int { 
    return 25 
} 

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView { 
     // use a custom view from nib 
     let view = Bundle.main.loadNibNamed("CarouselReuseView", owner: self, options: nil)![0] as! CarouselReuseView 
     view.frame.size = CGSize(width: self.view.frame.size.width/2, height: 83.0) 
     view.backgroundColor = UIColor.lightGray 

     let friend = friendList[index] as friend 
     view.lblName.text = friend.fullName 
     let url = friend.photo 
     let task = URLSession.shared.dataTask(with: URL(string: url)!, completionHandler: {data, response, error in 
      if error == nil { 
       DispatchQueue.main.async { 
        view.imageView.image = UIImage(data: data!) 
        view.imageView.layer.cornerRadius = view.imageView.frame.size.width/2 
        view.imageView.layer.masksToBounds = true 
       } 
      } 
     }) 
     task.resume() 
     return view 
    } 

} 

Objectiv C

@property (weak, nonatomic) IBOutlet iCarousel *carouselView; 


- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    _carouselView.type = iCarouselTypeInvertedWheel; 
    _carouselView.vertical = true; 
    _carouselView.delegate = self; 
    _carouselView.dataSource = self; 
    _carouselView.layer.masksToBounds = true; 
} 

iCarouselデータソース

ニブ

からカスタムビューを使用して、倒立車輪型と
@IBOutlet weak var viewCarousel: iCarousel! 

    override func viewDidLoad() { 
      super.viewDidLoad() 
     viewCarousel.type = .invertedWheel 
     viewCarousel.isVertical = true 
     viewCarousel.delegate = self 
     viewCarousel.dataSource = self 
    } 

をiCarouselを作成

-(NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel { 
    return 10; 
} 

-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view { 

    CustomView* myViewObject = [[[NSBundle mainBundle] loadNibNamed:@"customView" owner:self options:nil] objectAtIndex:0]; 

    myViewObject.lbl.text = [NSString stringWithFormat:@"%ld",(long)index]; 

    return myViewObject; 
} 

がここのCustomViewが私のUIViewのサブクラスと "のCustomView" である私はあなたが

詳細情報は、このヘルプを願っていUIViewのXIB名 です: - https://github.com/nicklockwood/iCarousel

+0

あなたは私がカウロを使用して同じ2つのビューを表示したいのですか? – Pavankumar

+0

私はあなたがObj cで同じ私を導くことができる迅速に気づいていないので??? – BhaviDev

+0

上記のコードでNIBとうまく動作しますが、私はストーリーボードでこれをどのように達成できますか? ? – BhaviDev

0

このお試しください:

-(UIView *) carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{ 
     UIView *globleView = (UIView *)view; 
     if (!globleView) { 
      globleView = [[[NSBundle mainBundle] loadNibNamed:@"yourView" owner:self options:nil] objectAtIndex:0];; 
      globleView.backgroundColor = [UIColor clearColor]; 
      UIImageView *imageView = [[UIImageView alloc]initWithFrame:globleView.frame]; 

      imageView.tag = 100; 
      [globleView addSubview:imageView]; 

      UILabel *lblFeatureRecipeName = [[UILabel alloc]initWithFrame:CGRectMake(15, ViewHeight(globleView) -50, ViewWidth(globleView)-40, 50)]; 

      lblFeatureRecipeName.tag = 101; 
      [globleView addSubview:lblFeatureRecipeName]; 
      if (index == 0) { 
       [self refreshCarousleViewWithView:globleView withIndex:index]; 
      } 
     } 
     return globleView; 
    } 
+0

しかし、私はどのようなinittisを作成する必要がありますテーブルビューのカスタムセルのようにcreatしたいだけでデータを割り当てるそのラベルとイメージはこのメソッドを使って作成したり追加したりしないでください。 – BhaviDev

+0

私はautolayoutを有効にするためにフレームを設定したくないので、それをストーリーボードから取るでしょう。 – BhaviDev

関連する問題