mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-08 00:47:41 +02:00
Add GrowingTextView to the project
This commit is contained in:
Vendored
Executable
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// GrowingTextViewExampleAppDelegate.h
|
||||
//
|
||||
// Created by Hans Pinckaers on 29-06-10.
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2011 Hans Pinckaers
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class GrowingTextViewExampleViewController;
|
||||
|
||||
@interface GrowingTextViewExampleAppDelegate : NSObject <UIApplicationDelegate> {
|
||||
UIWindow *window;
|
||||
GrowingTextViewExampleViewController *viewController;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) IBOutlet UIWindow *window;
|
||||
@property (nonatomic, strong) GrowingTextViewExampleViewController *viewController;
|
||||
|
||||
@end
|
||||
|
||||
Vendored
Executable
+104
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// GrowingTextViewExampleAppDelegate.m
|
||||
//
|
||||
// Created by Hans Pinckaers on 29-06-10.
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2011 Hans Pinckaers
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import "GrowingTextViewExampleAppDelegate.h"
|
||||
#import "GrowingTextViewExampleViewController.h"
|
||||
|
||||
@implementation GrowingTextViewExampleAppDelegate
|
||||
|
||||
@synthesize window;
|
||||
@synthesize viewController;
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
viewController = [[GrowingTextViewExampleViewController alloc] init];
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
[window addSubview:viewController.view];
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@end
|
||||
Vendored
Executable
+39
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// GrowingTextViewExampleViewController.h
|
||||
//
|
||||
// Created by Hans Pinckaers on 29-06-10.
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2011 Hans Pinckaers
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "HPGrowingTextView.h"
|
||||
|
||||
@interface GrowingTextViewExampleViewController : UIViewController <HPGrowingTextViewDelegate>{
|
||||
UIView *containerView;
|
||||
HPGrowingTextView *textView;
|
||||
}
|
||||
|
||||
-(void)resignTextView;
|
||||
|
||||
@end
|
||||
|
||||
Vendored
Executable
+202
@@ -0,0 +1,202 @@
|
||||
//
|
||||
// GrowingTextViewExampleViewController.m
|
||||
//
|
||||
// Created by Hans Pinckaers on 29-06-10.
|
||||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2011 Hans Pinckaers
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#import "GrowingTextViewExampleViewController.h"
|
||||
|
||||
@implementation GrowingTextViewExampleViewController
|
||||
|
||||
|
||||
-(id)init
|
||||
{
|
||||
self = [super init];
|
||||
if(self){
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardWillShow:)
|
||||
name:UIKeyboardWillShowNotification
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardWillHide:)
|
||||
name:UIKeyboardWillHideNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Implement loadView to create a view hierarchy programmatically, without using a nib.
|
||||
- (void)loadView {
|
||||
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
|
||||
self.view.backgroundColor = [UIColor colorWithRed:219.0f/255.0f green:226.0f/255.0f blue:237.0f/255.0f alpha:1];
|
||||
|
||||
containerView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40, 320, 40)];
|
||||
|
||||
textView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(6, 3, 240, 40)];
|
||||
textView.isScrollable = NO;
|
||||
textView.contentInset = UIEdgeInsetsMake(0, 5, 0, 5);
|
||||
|
||||
textView.minNumberOfLines = 1;
|
||||
textView.maxNumberOfLines = 6;
|
||||
// you can also set the maximum height in points with maxHeight
|
||||
// textView.maxHeight = 200.0f;
|
||||
textView.returnKeyType = UIReturnKeyGo; //just as an example
|
||||
textView.font = [UIFont systemFontOfSize:15.0f];
|
||||
textView.delegate = self;
|
||||
textView.internalTextView.scrollIndicatorInsets = UIEdgeInsetsMake(5, 0, 5, 0);
|
||||
textView.backgroundColor = [UIColor whiteColor];
|
||||
textView.placeholder = @"Type to see the textView grow!";
|
||||
|
||||
// textView.text = @"test\n\ntest";
|
||||
// textView.animateHeightChange = NO; //turns off animation
|
||||
|
||||
[self.view addSubview:containerView];
|
||||
|
||||
UIImage *rawEntryBackground = [UIImage imageNamed:@"MessageEntryInputField.png"];
|
||||
UIImage *entryBackground = [rawEntryBackground stretchableImageWithLeftCapWidth:13 topCapHeight:22];
|
||||
UIImageView *entryImageView = [[UIImageView alloc] initWithImage:entryBackground];
|
||||
entryImageView.frame = CGRectMake(5, 0, 248, 40);
|
||||
entryImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
||||
|
||||
UIImage *rawBackground = [UIImage imageNamed:@"MessageEntryBackground.png"];
|
||||
UIImage *background = [rawBackground stretchableImageWithLeftCapWidth:13 topCapHeight:22];
|
||||
UIImageView *imageView = [[UIImageView alloc] initWithImage:background];
|
||||
imageView.frame = CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height);
|
||||
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
|
||||
|
||||
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||
|
||||
// view hierachy
|
||||
[containerView addSubview:imageView];
|
||||
[containerView addSubview:textView];
|
||||
[containerView addSubview:entryImageView];
|
||||
|
||||
UIImage *sendBtnBackground = [[UIImage imageNamed:@"MessageEntrySendButton.png"] stretchableImageWithLeftCapWidth:13 topCapHeight:0];
|
||||
UIImage *selectedSendBtnBackground = [[UIImage imageNamed:@"MessageEntrySendButton.png"] stretchableImageWithLeftCapWidth:13 topCapHeight:0];
|
||||
|
||||
UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
doneBtn.frame = CGRectMake(containerView.frame.size.width - 69, 8, 63, 27);
|
||||
doneBtn.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
|
||||
[doneBtn setTitle:@"Done" forState:UIControlStateNormal];
|
||||
|
||||
[doneBtn setTitleShadowColor:[UIColor colorWithWhite:0 alpha:0.4] forState:UIControlStateNormal];
|
||||
doneBtn.titleLabel.shadowOffset = CGSizeMake (0.0, -1.0);
|
||||
doneBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18.0f];
|
||||
|
||||
[doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[doneBtn addTarget:self action:@selector(resignTextView) forControlEvents:UIControlEventTouchUpInside];
|
||||
[doneBtn setBackgroundImage:sendBtnBackground forState:UIControlStateNormal];
|
||||
[doneBtn setBackgroundImage:selectedSendBtnBackground forState:UIControlStateSelected];
|
||||
[containerView addSubview:doneBtn];
|
||||
containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
|
||||
}
|
||||
|
||||
-(void)resignTextView
|
||||
{
|
||||
[textView resignFirstResponder];
|
||||
}
|
||||
|
||||
//Code from Brett Schumann
|
||||
-(void) keyboardWillShow:(NSNotification *)note{
|
||||
// get keyboard size and loctaion
|
||||
CGRect keyboardBounds;
|
||||
[[note.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
|
||||
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
|
||||
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
|
||||
|
||||
// Need to translate the bounds to account for rotation.
|
||||
keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
|
||||
|
||||
// get a rect for the textView frame
|
||||
CGRect containerFrame = containerView.frame;
|
||||
containerFrame.origin.y = self.view.bounds.size.height - (keyboardBounds.size.height + containerFrame.size.height);
|
||||
// animations settings
|
||||
[UIView beginAnimations:nil context:NULL];
|
||||
[UIView setAnimationBeginsFromCurrentState:YES];
|
||||
[UIView setAnimationDuration:[duration doubleValue]];
|
||||
[UIView setAnimationCurve:[curve intValue]];
|
||||
|
||||
// set views with new info
|
||||
containerView.frame = containerFrame;
|
||||
|
||||
|
||||
// commit animations
|
||||
[UIView commitAnimations];
|
||||
}
|
||||
|
||||
-(void) keyboardWillHide:(NSNotification *)note{
|
||||
NSNumber *duration = [note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
|
||||
NSNumber *curve = [note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
|
||||
|
||||
// get a rect for the textView frame
|
||||
CGRect containerFrame = containerView.frame;
|
||||
containerFrame.origin.y = self.view.bounds.size.height - containerFrame.size.height;
|
||||
|
||||
// animations settings
|
||||
[UIView beginAnimations:nil context:NULL];
|
||||
[UIView setAnimationBeginsFromCurrentState:YES];
|
||||
[UIView setAnimationDuration:[duration doubleValue]];
|
||||
[UIView setAnimationCurve:[curve intValue]];
|
||||
|
||||
// set views with new info
|
||||
containerView.frame = containerFrame;
|
||||
|
||||
// commit animations
|
||||
[UIView commitAnimations];
|
||||
}
|
||||
|
||||
- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height
|
||||
{
|
||||
float diff = (growingTextView.frame.size.height - height);
|
||||
|
||||
CGRect r = containerView.frame;
|
||||
r.size.height -= diff;
|
||||
r.origin.y += diff;
|
||||
containerView.frame = r;
|
||||
}
|
||||
|
||||
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
// Release any retained subviews of the main view.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user