Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Here is my image.I want to create a tip balloon like this. This must visible when user types in textfield
I have created one more but that is in cloud shape. Please help to create this
Subclass the UITextField then override becomeFirstResponder (show bubble) and resignFirstResponder (hide bubble) and when the field is active present your bubble.
.h
#import <UIKit/UIKit.h>
#interface BubbleTextField : UITextField
#end
.m
#import "BubbleTextField.h"
#interface BubbleTextField ()
{
UIView *_bubbleView;
}
- (void)showBubble:(BOOL)show;
#end
#implementation BubbleTextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialize the _bubbleView here
}
return self;
}
#pragma mark - Override
- (BOOL)becomeFirstResponder {
BOOL shouldBecome = [super becomeFirstResponder];
if (shouldBecome)
{
[self showBubble:YES];
}
return shouldBecome;
}
- (BOOL)resignFirstResponder {
BOOL shouldResign = [super resignFirstResponder];
if (shouldResign)
{
[self showBubble:NO];
}
return shouldResign;
}
#pragma mark - Private Methods
- (void)showBubble:(BOOL)show {
// Show/Hide
// Animations etc.
}
#end
Check out KBPopupBubble.
And CMPopTipView
Also, check out these search results for custom controls on cocoa controls. Search Results.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This might be simple, but I'm very new at developing an iOS APP. I have an UIButton and three UIImage's. What I'm trying to do is that when the user taps the button, the first image will display, if the user taps it again, then show the second image, and so on. When the last image is displaying, then go back to the first one when tapping the button again. The problem is that only the first image appears.
Here is my code:
file.h
#interface ViewController : UIViewController
{
IBOutlet UIImageView *images;
}
-(IBAction)changeImage:(id)sender;
#end
file.m
#implementation ViewController
-(IBAction)changeImage:(id)sender{
images.image = [UIImage imageNamed:#"pic1.png"], [UIImage imageNamed:#"pic2.png"],[UIImage imageNamed:#"pic3.png"];
}
Any help would be greatly appreciated!
Than you in advance!
You can declare a global variable for the index and global variable array to hold the image names
self.index = 0;
self.imageList = [NSArray arrayWithObjects:#"pic1", #"pic2", #"pic3", nil];
then in the click action, you can do
-(IBAction)changeImage:(id)sender{
images.image = [UImage imageNamed:self.imageList[self.index]];
self.index = (self.index + 1 ) % [self.imageList count];
}
I don't have the compiler with me to verify the syntax, but you get the idea.
This is easy, create a counter called tapCounter in viewDidLoad. Let's imagine you already set your image array as follows in viewDidLoad. Make sure images and tapCounter are properties of your class
- (void)viewDidLoad {
[super viewDidLoad];
self.images = #[[UIImage imageNamed:#"pic1.png"], [UIImage imageNamed:#"pic2.png"],[UIImage imageNamed:#"pic3.png"]];
self.tapCounter = 0;
}
-(IBAction)changeImage:(id)sender {
UIButton *but = (UIButton *)sender;
tapCounter++;
if (tapCounter == 4) {
tapCounter = 1;
}
[but setBackgroundImage:[images objectAtIndex:tapCounter-1] forState:UIControlStateNormal];
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hi guys i am trying to make a window with a view controller (which i guess is like GroupBox in .Net (fix me if i'm wrong..)) and i was trying to start the application on the simulator and it threw an exception. I am using storyboards.
#interface ViewController ()
#end
#implementation ViewController
-(id)init
{
self = [super init];
self.arSongsCollection = [[NSMutableArray alloc] init];
_tableView.delegate = self;
_tableView.dataSource = self.arSongsCollection;
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_arSongsCollection addObject:[[Song alloc] initWithTitle:#"Song" andArtist:#"Artist" andURL:[NSURL URLWithString:#"http://songurl.com/song.mp3"]]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Read more about tableview datasources, here's the problem:
_tableView.dataSource = self.arSongsCollection;
this ususally should also point to self
_tableView.dataSource = self;
and you have to implement both necessary tableview delegate and dataSource methods in the view controller class.
I have an UITextField to search the word that typed there. I set the returnKeyType as UIReturnKeySearch. But I couldn't figure how to bind a function that I created, to the "Search" button at the keyboard.
self.searchWord.returnKeyType=UIReturnKeySearch;
How can I do that? Thanks.
If I'm understanding correctly you need to implement the UITextfield delegate:
In your header file
#interface MyViewController : UIViewController <UITextFieldDelegate>
in viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
self.searchTextField.delegate = self;
}
Then implement the delegate method.
- (BOOL)textFieldShouldReturn:(UITextField *)aTextfield {
// Only do search when user hits return key on the search textfield.
if ([aTextfield isEqual:self.searchTextField]) {
// Method that does the search.
[self doSearch];
}
return YES;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to call a function in a UIView subclass of an item added to the main window, when the device rotate.
I've many items so I don't want to call such method one by one, but I want it automatically invoked for this item and all subviews.
thanks
To get the automatic subview behavior, declare a UIView category adding the method you wish to be invoked. Then have your view subscribe to device rotation notifications, and as part of its handling of the notification, call that same method on all its subviews. Something like this (typed without benefit of autocorrect or compiled, so please take as an illustration and not a full example program):
#interface UIView (MyAppAdditions)
- (void)rotationDetected;
#end
#implementation UIView (MyAppAdditions)
- (void)rotationDetected
{
}
#end
#implementation MyView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
return self;
}
- (void)didRotate:(NSNotification *)notification
{
[self rotationDetected];
[self.subviews makeObjectsPerformSelector:#selector(rotationDetected)];
}
#end
A more flexible implementation would also override initWithCoder: or awakeFromNib to subscribe the rotation notification as well.
I've a TTTableViewController which follows TTTableViewController -> TTDataSource -> TTModel pattern. I've TTTableMoreButton and my list goes on to load more items when the user clicks on it.
How can I change the behaviour of this TTTableMoreButton? When the user came to the end of the list, I want it to behave as if it is clicked. In Facebook app, there is an implementation like this. I hope I could tell what I want.
Here is how to do it.
full disclosure: It is my code blog.
Here I've my own approach which i found out just before coneybeare's answer. I simply subclassed TTTableMoreButton and TTTableMoreButtonCell classes and in the "- (void)layoutSubviews" method, I detect that "Load More" button is appearing, and it should start loading more data if it is not already doing it.
I'm not sure which approach (coneybeaare's or mine) is the best and I'm looking forward for the comments about it.
AutoMoreTableItem.h
#interface AutoMoreTableItem : TTTableMoreButton {
}
#end
AutoMoreTableItem.m
#import "AutoMoreTableItem.h"
#implementation AutoMoreTableItem
#end
AutoMoreTableItemCell.h
#interface AutoMoreTableItemCell : TTTableMoreButtonCell {
}
#end
AutoMoreTableItemCell.m
#import "AutoMoreTableItemCell.h"
#import "AutoMoreTableItem.h"
#implementation AutoMoreTableItemCell
- (void)setObject:(id)object {
if (_item != object) {
[super setObject:object];
AutoMoreTableItem* item = object;
self.animating = item.isLoading;
self.textLabel.textColor = TTSTYLEVAR(moreLinkTextColor);
self.selectionStyle = TTSTYLEVAR(tableSelectionStyle);
self.accessoryType = UITableViewCellAccessoryNone;
}
}
- (void)layoutSubviews {
[super layoutSubviews];
AutoMoreTableItem* moreLink = self.object;
if(moreLink.isLoading ==YES) {
return;
}
if (moreLink.model) {
moreLink.isLoading = YES;
self.animating = YES;
[moreLink.model load:TTURLRequestCachePolicyDefault more:YES];
}
}
#end
And of course, in the datasource implementation:
- (Class)tableView:(UITableView*)tableView cellClassForObject:(id) object {
if([object isKindOfClass:[AutoMoreTableItem class]]){
return [AutoMoreTableItemCell class];
} else {
return [super tableView:tableView cellClassForObject:object];
}
}