IOS UI?

Monkey Targets Forums/iOS/IOS UI?

CopperCircle(Posted 2011) [#1]
Hi, I am trying to get IOS buttons working using this native code posted by xzess in another thread, when compiling I get superView not declared? Any ideas?




CopperCircle(Posted 2011) [#2]
I have got this working basically now, here is the .cpp code

void UICreateButton(String text, float x1,float y1, float x2, float y2)
{
	UIButton    *myButton;
	NSString *StrText = text.ToNSString();

	myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	myButton.frame = CGRectMake(x1, y1, x2, y2); // position in the parent view and set the size of the button
	[myButton setTitle:StrText forState:UIControlStateNormal];
	// add targets and actions
    
	//[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
	// Add Subview to mojo window
	[[[UIApplication sharedApplication] keyWindow] addSubview:myButton];
}

void UICreateTextField(String placeholder, float x1,float y1, float x2, float y2)
{
   UITextField    *textfield;
   NSString *placeholderStr = placeholder.ToNSString();

   // Create textfield 
   textfield = [[UITextField alloc] initWithFrame:CGRectMake(x1, y1, x2, y2)];
   textfield.placeholder = placeholderStr;
   //textfield.delegate = self;
   textfield.returnKeyType = UIReturnKeyDone;
   textfield.borderStyle = UITextBorderStyleBezel;
   textfield.enablesReturnKeyAutomatically = TRUE;
   // Add Subview to mojo window
	[[[UIApplication sharedApplication] keyWindow] addSubview:textfield];
}

void UICreateScrollView(float ScrollViewWidth, float ScrollViewHeight, float ContentWidth, float ContentHeight)
{
	UIScrollView		*scrollview;
		
	// Create scrollview
	scrollview = [[UIScrollView alloc] init];      
	scrollview.contentSize = CGSizeMake(ContentWidth, ContentHeight);
	scrollview.frame = CGRectMake(0, 0, ScrollViewWidth, ScrollViewHeight);
	scrollview.scrollsToTop = NO;
	//scrollview.delegate = self;
	// Add Subview to mojo window
	[[[UIApplication sharedApplication] keyWindow] addSubview:scrollview];
}


Add to the imonk.monkey file

Function UICreateButton(text$,x1#,y1#,x2#,y2#)
Function UICreateTextField(placeholder$, x1#, y1#, x2#,y2#)
Function UICreateScrollView(ScrollViewWidth#,ScrollViewHeight#,ContentWidth#, ContentHeight#)



Rob Pearmain(Posted 2011) [#3]
Excellent, well done

You worked out how to respond to button clicks etc?


John McCubbin(Posted 2013) [#4]
I know this is an old thread but over the last couple of days I have been messing around with trying to get some native iOS elements working in monkey, the code I came up with looks pretty similar to the code above, but it does not create useful UI elements which can be accessed via monkey.
I can create buttons, scrollviews, switches, sliders etc but without having the ability to then use them in monkey the usefulness is limited.

Has anyone had any success creating and using native iOS UI elements from within monkey lately?

Cheers