I am developing an iPhone application that allows user to draw emoticons and use it while comments with text (like iPhone allows user to use their emoji by enabling emoji keyboard from the settings). I want to use my own made emoticons. I store all emoticons in collection view. How can I enable that view from iPhone default keyboard, so that I can use my own custom emoticons with text?
When using a custom keyboard in your app, just use the inputView attribute of a UITextField.
You can do this in the following fashion:
#interface SCAViewController ()
#property (weak, nonatomic) IBOutlet UITextField *textField;
#property ( nonatomic) UIView *labelView;
#end
#implementation SCAViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// here we set the keyboard to become the first responder
// this is optional...
//[_textField becomeFirstResponder];
// creating the custom label keyboard
_labelView = [[UIView alloc] initWithFrame:CGRectMake(0, 568, 320, 568/3)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
label.text = #"Label View!";
[_labelView addSubview:label];
_labelView.backgroundColor = [UIColor blueColor];
_textField.inputView = _labelView;
}
Now for the explanation:
The reason that the _labelView is set to those current dimensions is because i wanted a close match to the default keyboard. You can always change them to whatever you're needing.
I did a label being added onto the view, but since you're doing emojis, i'd create a method that will load the image into the textField by using buttons.
It would be list like the following:
create action method for button
create button
set background image of button
add button onto custom view
set inputView to the custom view
you can create the action method like so
// create the method for the button
- (IBAction) loadOntoKeyboard {
// load the image/text/whatever else into the textfield
}
you can create a button to add onto your custom view like
// creating custom button
UIButton *emoji1 = [UIButton buttonWithType:UIButtonTypeCustom];
// creating frame for button.
// x - the location of the button in x coordinate plane
// y - same as x, but on y plane
// width - width of button
// height - height of button
emoji1.frame = CGRectMake(x, y, width, height);
// just setting background image here
[emoji1 setBackgroundImage:[UIImage imageNamed:#"emoji_imageā¦"] forState:UIControlStateNormal];
// don't forget to add target of button
[emoji1 addTarget:self action:#selector(loadOntoKeyboard) forControlEvents:UIControlEventTouchUpInside];
// adding button onto view
[customView addSubview:emoji1];
// setting the inputView to the custom view where you added the buttons
textFieldVariable.inputView = customView;
Hopefully this all makes sense to you, and I hope that I helped you understand in a clear manner on how to implement the custom keyboard actions :)
Hope this helps!
Related
I am developing an application in which I have a horizontal scroller.
The scroller area comprise of different colors [which are nothing but UIImageView of colors].
Above the scroller area is a canvas [which is also a UIImageView].
Now, what I want is that when I select any color in the scroller area, it should set on the canvas.
It is pretty much like a color picker but I am already providing solid color options to be selected by the user.
How should I go about it ? Any sample Code to get me started or my mind kicking would be awesome ?
Thanx a ton
To implement it easily.
Use UIView not UIImageView
Set UIView backgroundColor and place it on the scroll
Set UITapGestureRecognizer on views,Refer here
when a purticular view is touched you have its instance of view which
is touched
get the background color of the view and set it in the scroller
Can you take UIButtons instead of UIImageViews inside your scrollView to show colours to be picked.
This will make the implementation easier. User will select any colour button and you will receive a callback in buttons action selector method. Then based on button tag or any property you can set the colour to your canvas.
In current implementation it will be tricky as you need to know the exact content offset where the tap is done to make out which UIImageView was pressed.
coding steps:
In your scroll view add UIButtons instead of UIImageView like:
UIButton* button = [[UIButton alloc] initWithFrame:someRect];
//put some tag to button
button.tag = someInt;
//add selector to each button to get callback
[view addTarget:self action:#selector(btnSelected:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
In the btnSelected method put this code:
-(IBAction)btnSelected:(id)sender;
{
UIButton* button = (UIButton*) sender;
if (button.tag == someInt) {
//do something like
canvas.backgroundColor = button.backgroundColor;
}
}
Instead of using UIImageViews or UIViews as suggested, I would put custom UIButtons for picking colors.
UIButton * colorButton;
//You will probably do these inside a for loop
colorButton = [UIButton buttonWithType:UIButtonTypeCustom];
[colorButton setFrame:CGRectMake(X, Y, buttonSize, buttonSize)];
[colorButton setTitle:#"" forState:UIControlStateNormal];
[colorButton setBackgroundColor:SOME_COLOR];
//Border visualization would be good if you are putting buttons side-by-side
[colorButton.layer setBorderWidth:1.0];
[colorButton.layer setBorderColor:[[UIColor darkGrayColor] CGColor]];
//You can use this tag to identify different buttons later
[colorButton setTag:INDEX+SOME_OFFSET]; //use loop index with some offset
[colorButton addTarget:self action:#selector(colorButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
-(void) colorButtonPressed:(UIButton *) sender
{
UIColor *selectedColor = sender.backgroundColor; //Or identify with sender.tag
[yourCanvas doSmtOnCanvas:selectedColor];
}
Initialize UIImageView then add gesture recognizer to all imageViews by calling this method.
- (void) setupImageView : (UIImageView *) imageView{
[imageView setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(changeUIImageViewBackgroundColor:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[imageView addGestureRecognizer:tapGestureRecognizer];
}
Now change color of canvasView within the selector by following way:
- (void) changeUIImageViewBackgroundColor : (UITapGestureRecognizer *) recognizer{
UIImageView *imageView = (UIImageView *)[recognizer view];
[canvasView setBackgroundColor:[imageView backgroundColor]];
}
You can put a tap gesture in your scrollview and whenever a tap is made in the scroll check whether the tap is on the imageview. (You will get whether the tap point in on imageview or not) and according you can change the image.
Second alternative is to take a custom button and handle on its click.
Hope it helps
i need to place menu button in iphone.
i have some touch with android.
In android i display like this by pressing menu.
Is it possible to handle iphone menu button.
if it is not where can i place these.
Thank u in advance.
use the round rect button and change the property into custom place the image as the background image of the button do this for more menu item in your home page.
this is the way i do the menu item.......
I think with Xcode and Interface Builder (iPhone's development platform), getting this task done would be even simpler.
As a brief introduction to iPhone app's UI design, to place this tab bar (as you put it, the menu) on a view, all you need to do is pick up a tab bar from the library and place it on a nib file's view. You can also connect such a tab bar with some codes responsible for internal logic by simply clicking and dragging. It's simple.
btw, a nib file is just some file format Xcode and Interface Builder use to hold the UI data.
iPhones don't have a dedicated slide out menu - everything is on the screen at all times, and there are no purpose built buttons (like back and home).
You should either always show your actions on the screen, or if they are unimportant or infrequent, hide them behind another action button (like a + or wrench icon).
You should use images same as menu items and put custom button over the images.This is the only way to show menu as you want.
Iphone sdk provides tabBar and toolBar, you also can use these in customize forms.This is the correct way to making menu.Iphone design pattern having lot of strengths over android so you can make every thing in Iphone easily but you cant make every thing in android same as iPhone.Iphone having international standards so must use iPhone's controls.
.h
IBOutlet UIScrollView *scrollView;
#property ( nonatomic , retain ) IBOutlet UIScrollView *scrollView;
-(void)AppleVijayAtFacebookDotCom:(id)sender;
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons;
.m
#synthesize scrollView;
-(void)AppleVijayAtFacebookDotCom:(id)sender{
NSLog(#"AppleVijayAtFacebookDotCom called");
UIButton *button=(UIButton *)sender;
if (button.tag == 0) {
NSLog(#"hey have clicked first button, this is my tag : %i \n\n",button.tag);
}
else if (button.tag == 1) {
NSLog(#"hey have clicked second button, this is my tag : %i \n\n",button.tag);
}
// ......like this
NSLog(#"button clicked is : %iBut \n\n",button.tag);
}
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{
for (int i = 0; i < totalNoOfButtons; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:#selector(AppleVijayAtFacebookDotCom:) forControlEvents:UIControlEventTouchUpInside];
//[button1 setImage:[UIImage imageNamed:#"Button.png"] forState:UIControlStateNormal];//with image
//OR
[button setTitle:[NSString stringWithFormat:#"%iBut",i] forState:UIControlStateNormal];//with title
button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height);
button.clipsToBounds = YES;
button.showsTouchWhenHighlighted=YES;
button.layer.cornerRadius = 10;//half of the width
button.layer.borderColor=[UIColor redColor].CGColor;
button.layer.backgroundColor=[UIColor blackColor].CGColor;
button.layer.borderWidth=2.0f;
button.tag=i;
[self.scrollView addSubview:button];
}
self.scrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height);
//self.navigationItem.titleView=self.scrollView;//if u have navigationcontroller then enable this line
}
Dont forget to connect the scrollView in interface builder
while creating the scrollview in IB make sure ur scrollView height is 44.which is default to navigation bar.so it will look nice.
in viewDidLoad call
[self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:30];
OUTPUT
I have a view based app and I would like to implement one of those sliding menus (I don't know if there's a specific name to call them), like Mail.
The idea is this: I have a board with several objects. When the user taps and hold on a object for half a second a popover appears showing the object properties. The properties are: object color, object text, object text color and object shadow color.
Every of these 4 properties, when tapped, will make a new window slide from right into the popover, bringing the adjustments. Tap done and the view is pushed to the right bringing the first view again... the process repeats for all views.
how do I add these "sliding menus" to a view based app inside a popover?
thanks in advance
Are you talking about iPhone or iPad? Your tag is only for iPhone.
On the iPad, there's a specific UI element called a Popover. When you click on the "Reply" icon in Mail, a menu appears with "Reply" and "Forward". This is a Popover. On iPhone, there's another kind of UI element, used for example when you want to copy text. It shows "Select", "Cut" and so on. That's called a Callout. Note that you can't use Popovers on the iPhone.
If you're talking about Mail on the iPhone, you have to find out how to use a UINavigationController, and then use the method -pushViewController:animated: to make a new page slide onto the screen.
its the default animation for UINavigationController. so if you implement a UINavigationController as your root view for your UIPopoverController, then push the view controllers you want, it should be the desired effect.
.h
IBOutlet UIScrollView *scrollView;
#property ( nonatomic , retain ) IBOutlet UIScrollView *scrollView;
-(void)AppleVijayAtFacebookDotCom:(id)sender;
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons;
.m
#synthesize scrollView;
-(void)AppleVijayAtFacebookDotCom:(id)sender{
NSLog(#"AppleVijayAtFacebookDotCom called");
UIButton *button=(UIButton *)sender;
if (button.tag == 0) {
NSLog(#"hey have clicked first button, this is my tag : %i \n\n",button.tag);
}
else if (button.tag == 1) {
NSLog(#"hey have clicked second button, this is my tag : %i \n\n",button.tag);
}
// ......like this
NSLog(#"button clicked is : %iBut \n\n",button.tag);
}
-(void)createMenuWithButtonSize:(CGSize)buttonSize withOffset:(CGFloat)offset noOfButtons:(int)totalNoOfButtons{
for (int i = 0; i < totalNoOfButtons; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:#selector(AppleVijayAtFacebookDotCom:) forControlEvents:UIControlEventTouchUpInside];
//[button1 setImage:[UIImage imageNamed:#"Button.png"] forState:UIControlStateNormal];//with image
//OR
[button setTitle:[NSString stringWithFormat:#"%iBut",i] forState:UIControlStateNormal];//with title
button.frame = CGRectMake(i*(offset+buttonSize.width), 8.0, buttonSize.width, buttonSize.height);
button.clipsToBounds = YES;
button.showsTouchWhenHighlighted=YES;
button.layer.cornerRadius = 10;//half of the width
button.layer.borderColor=[UIColor redColor].CGColor;
button.layer.backgroundColor=[UIColor blackColor].CGColor;
button.layer.borderWidth=2.0f;
button.tag=i;
[self.scrollView addSubview:button];
}
self.scrollView.contentSize=CGSizeMake((buttonSize.width + offset) * totalNoOfButtons, buttonSize.height);
//self.navigationItem.titleView=self.scrollView;//if u have navigationcontroller then enable this line
}
Dont forget to connect the scrollView in interface builder
while creating the scrollview in IB make sure ur scrollView height is 44.which is default to navigation bar.so it will look nice.
in viewDidLoad call
[self createMenuWithButtonSize:CGSizeMake(70.0, 30.0) withOffset:20.0f noOfButtons:30];
OUTPUT
For some reason, the button initialized in the addBook method of my viewController won't respond to touches. The selector I've assigned to it never triggers, nor does the UIControlStateHighlighted image ever appear when tapping on the image.
Is there something intercepting touches before they get to the UIButton, or is its interactivity somehow disabled by what I'm doing to it?
- (void)viewDidLoad {
...
_scrollView.contentSize = CGSizeMake(currentPageSize.width, currentPageSize.height);
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollsToTop = NO;
_scrollView.pagingEnabled = YES;
...
}
- (void)addBook {
// Make a view to anchor the UIButton
CGRect frame = CGRectMake(0, 0, currentPageSize.width, currentPageSize.height);
UIImageView* bookView = [[UIImageView alloc] initWithFrame:frame];
// Make the button
frame = CGRectMake(100, 50, 184, 157);
UIButton* button = [[UIButton alloc] initWithFrame:frame];
UIImage* bookImage = [UIImage imageNamed:kBookImage0];
// THIS SECTION NOT WORKING!
[button setBackgroundImage:bookImage forState:UIControlStateNormal];
UIImage* bookHighlight = [UIImage imageNamed:kBookImage1];
[button setBackgroundImage:bookHighlight forState:UIControlStateHighlighted];
[button addTarget:self action:#selector(removeBook) forControlEvents:UIControlEventTouchUpInside];
[bookView addSubview:button];
[button release];
[bookView autorelease];
// Add the new view/button combo to the scrollview.
// THIS WORKS VISUALLY, BUT THE BUTTON IS UNRESPONSIVE :(
[_scrollView addSubview:bookView];
}
- (void)removeBook {
NSLog(#"in removeBook");
}
The view hierarchy looks like this in Interface Builder:
UIWindow
UINavigationController
RootViewController
UIView
UIScrollView
UIPageControl
and presumably like this once the addBook method runs:
UIWindow
UINavigationController
RootViewController
UIView
UIScrollView
UIView
UIButton
UIPageControl
THe UIScrollView might be catching all the touch events.
Maybe try a combination of the following:
_scrollView.delaysContentTouches = NO;
_scrollView.canCancelContentTouches = NO;
and
bookView.userInteractionEnabled = YES;
try to remove the [bookView autorelease]; and do it like this:
// Add the new view/button combo to the scrollview.
// THIS WORKS VISUALLY, BUT THE BUTTON IS UNRESPONSIVE :(
[_scrollView addSubview:bookView];
[bookView release];
_scrollView.canCancelContentTouches = YES; should do the trick
delaysContentTouches - is a Boolean value that determines whether the scroll view delays the handling of touch-down gestures. If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is NO , the scroll view immediately calls touchesShouldBegin:withEvent:inContentView:. The default value is YES.
canCancelContentTouches - is a Boolean value that controls whether touches in the content view always lead to tracking. If the value of this property is YES and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll. If the value of this property is NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.
I want to add UILabel controls to my application dynamically from code (programmatically), please help me
You can do it the following way in one of the view controller methods:
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(...)]; // Create UILabel
myLabel.tag = someTag; // set label's tag to access this label in future via [view viewWithTag:someTag];
... // set label's properties like text, background and text color, font size etc (e.g. myLabel.textColor = [UIColor redColor];)
[view addSubView:myLabel]; // add label to your view
[myLabel release]; // view owns the label now so we can release it