Skip to content

Instantly share code, notes, and snippets.

@Dunemaster
Last active August 29, 2015 14:22
Show Gist options
  • Save Dunemaster/27cacb771d5bfc446085 to your computer and use it in GitHub Desktop.
Save Dunemaster/27cacb771d5bfc446085 to your computer and use it in GitHub Desktop.
package com.some.ios;
import org.robovm.apple.coregraphics.CGRect;
import org.robovm.apple.foundation.NSIndexPath;
import org.robovm.apple.uikit.*;
public class MyViewController extends UIViewController {
private final UIButton button;
private final UILabel label;
private final UICollectionView collectionView;
private final UICollectionViewDataSource dataSource;
public MyViewController() {
// Get the view of this view controller.
UIView view = getView();
// Setup background.
view.setBackgroundColor(UIColor.white());
// Setup label.
label = new UILabel(new CGRect(10, 100, 300, 100));
label.setFont(UIFont.getSystemFont(24));
label.setTextAlignment(NSTextAlignment.Center);
label.setNumberOfLines(2);
view.addSubview(label);
// Setup button.
button = UIButton.create(UIButtonType.RoundedRect);
button.setFrame(new CGRect(110, 50, 100, 40));
button.setTitle("Start test", UIControlState.Normal);
button.getTitleLabel().setFont(UIFont.getBoldSystemFont(22));
button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
@Override
public void onTouchUpInside (UIControl control, UIEvent event) {
//...doing smth
}
});
view.addSubview(button);
collectionView = new UICollectionView(new CGRect(10, 215, 300, 250),
new UICollectionViewFlowLayout());
dataSource = new UICollectionViewDataSource() {
@Override
public long getNumberOfItemsInSection(UICollectionView collectionView, long section) {
return 5;
}
@Override
public UICollectionViewCell getCellForItem(UICollectionView collectionView, NSIndexPath indexPath) {
return null;
}
@Override
public long getNumberOfSections(UICollectionView collectionView) {
return 0;
}
@Override
public UICollectionReusableView getViewForSupplementaryElement(UICollectionView collectionView, String kind, NSIndexPath indexPath) {
return null;
}
};
collectionView.setDataSource(dataSource);
view.addSubview(collectionView);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment