I'm working on a titanium project. In which I need a customized searchbar like below.
But when I created the searchbar it looks like;
I want to change the image of cancel button. I searched a lot for customizing the searchbar in titanium, but couldn't find any solutions.
I'm creating searchbar in the following way:
var searchLocation = Ti.UI.createSearchBar({
showCancel:true,
height:55,
top:45,
width:'102%',
backgroundImage:"../../Images/bg_search.png",
borderRadius:'5'
});
Then I tried something different.
I created a view, a searchbar without cancel button and a customized button.
Added the searchbar to that view
Added the button to right of that searchbar.
//holder view
var searchHolder = Ti.UI.createView({
height : 55,
width : '100%',
top : 45,
backgroundImage:"../../Images/bg_header#2x.png",
layout : 'horizontal'
});
//search bar
var serLocation = Ti.UI.createSearchBar({
height:55,
top:0,
width:'85%',
backgroundImage:"../../Images/bg_header#2x.png"
});
//Calendar button
var calButton = Ti.UI.createButton({
height : 45,
width : 45,
backgroundImage:"../../Images/nav_calendar.png"
});
searchHolder.add(serLocation);
searchHolder.add(calButton );
It's working perfectly.
But I'm searching for any alternative solutions. Is there any built-in-methods to do this ?
Thanks in advance.
There aren't bult-in-methods for this. Your working solution is the best one.
Related
The title is pretty self explanatory, on iOS 10.3 using a UIBarButtonItem with a custom view (in this case UIStackView) assigned to a LeftBarButtonItem of a NavigationBar is not visible on iOS 11. I haven't figure out why it is not showed but when I type something with the keyboard my logic of the TextChanged event works! So the UISearchView is there but it is not visible:
Here is some code (It is coded with C# but it is using Objective C methods.):
var width = NavigationController.NavigationBar.Frame.Width;
var height = NavigationController.NavigationBar.Frame.Height;
_searchBarContainer = new UIStackView(new CGRect(0, 0, width * 0.75, height))
{
Alignment = UIStackViewAlignment.Center,
Axis = UILayoutConstraintAxis.Horizontal,
Spacing = 3
};
_uiSearchBar = new UISearchBar
{
BackgroundColor = UIColor.Clear,
BarTintColor = UIColor.Clear,
BackgroundImage = new UIImage(),
Placeholder = Strings.Search
};
_uiSearchBar.SizeToFit();
if (_iOS11)
{
_uiSearchBar.HeightAnchor.ConstraintEqualTo(44).Active = true;
}
_searchbarButtonItem = new UIBarButtonItem(_searchBarContainer);
NavigationItem.SetLeftBarButtonItem(_searchbarButtonItem, true);
ParentViewController.NavigationItem.LeftBarButtonItem = NavigationItem.LeftBarButtonItem;
Using the same code on iOS 10 this works.
Please try out setting up constraints to size properly your _searchBarContainer before setting it as the left bar button item. From iOS11 navigations bars use auto layout. Make sure you only add the constraints if iOS 11 is present, I was having problems in iOS 9 navigation bars otherwise.
Also checkout this thread in the Dev forum where it's explained how the bar items are wrapped inside stack views, maybe also helps with your particular issue.
I want to make something similar to the dropdown menu in these screenshots. How would I go about doing that?
When you tap the title, the arrow points up and a menu drops down. The App Is College Menus.
There are lots of cocoacontrols to perform this function in your app:
DropDown Menu Controls For iOS
But I think lmdropdownview is the most accurate.
My mistake, btnavigationdropdownmenu ITS the most accurate for what you are asking (according to your screens).
Implementation (Swift)[See the readme for more speceific instructions, and customization]:
let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"]
let menuView = BTNavigationDropdownMenu(frame: CGRectMake(0.0, 0.0, 300, 44), title: items.first!, items: items, containerView: self.view)
self.navigationItem.titleView = menuView
menuView.didSelectItemAtIndexHandler = {(indexPath: Int) -> () in
println("Did select item at index: \(indexPath)")
self.selectedCellLabel.text = items[indexPath]
}
Hope it helps.
EDIT:
Thanks for 'rsc' for the info, theres an objective-c version of this cocoacontrol:
#import "PFNavigationDropdownMenu.h"
-(void)viewDidLoad{
PFNavigationDropdownMenu *menuView = [[PFNavigationDropdownMenu alloc]initWithFrame:CGRectMake(0, 0, 300, 44)title:items.firstObjects items:items containerView:self.view];
menuView.didSelectItemAtIndexHandler = ^(NSUInteger indexPath){
NSLog(#"Did select item at index: %ld", indexPath);
self.selectedCellLabel.text = items[indexPath];
};
self.navigationItem.titleView = menuView;
}
Possible workaround if you prefer doing it manually:
Create two UIButton (up/down), assign the first one to navigationItem.titleView, add action for UIControlEventTouchUpInside on this action check if states changing to expanding or collapsing and dependent on that add/remove UITableView with empty dataSource on top of your UIViewController view, set proper frame. Then update datasource and either reload with row animation UITableViewRowAnimationBottom or UITableViewRowAnimationTop dependent on if it's expanding or collapsing. Replace button with second one.
I want the textarea to scroll horizontally once the test string has exceeded the width of the textarea. I tried the below code, but however, it does not work for some reason.
I also tried adding a wrapper view to scroll view and adding the textarea to the wrapper view; but that does not work either.
How can I fix this ?
var scroll = Ti.UI.createScrollView({
top:40,
left:230,
width:290,
height:50
});
win.add(scroll);
var textType = Ti.UI.createTextArea({
backgroundColor:'#E6E6E6',
borderColor:'blue',
borderRadius:10,
top:0,
left:0,
width:290,
height:50,
font:{fontSize:26, fontFamily:customFont},
editable:false,
enabled:false,
textAlign:'right',
scrollable:true
});
scroll.add(textType);
I know that this sound really simple but, for default the text area is vertical scrollable. and this is the only behavior i know of it. i have tried different properties like:
layout:"horizontal",
horizontalWrap:true,
scrollable:true,
But this has not resolve the issue.
I am designing a flashcard app using titanium appcelerator, the final aim is to use a scrollable view to display each card in the 'pack' and then on tapping a single card (i.e. the card in view) this should rotate about it's axis (i.e. flip over) to reveal the reverse.
You can see from the diagram below what I am hoping to achieve.
Unfortunately when tap one of the panels, instead of it's child view animating, instead the last child in the scrollableview animates.
I understand this is something to do with the fact that I am assigning variables in a loop but if someone can look at my code and tell me what I am doing wrong that would be great.
In JQuery it would look something like this
$(FrontView).click(function(){
$(this).parent().flip() //how do I access $(this) and $(this).parent() in Appcelerator?
});
Here is my appcelerator code:
while(rows.isValidRow()){
var FrontView = Ti.UI.createView({
backgroundImage: '/global/card_bg.png',
width: 295,
height:297
});
var BackView = Ti.UI.createView({
backgroundImage: '/global/card_bg.png',
width: 295,
height:297
});
var ControlView = Titanium.UI.createView({
backgroundColor:"#333",
bubbleParent : false,
width: 295,
height:297,
top : 100
});
FrontView.addEventListener('singletap', function() {
Ti.API.info('singletap');
ControlView.animate({view:BackView,transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT});
});
BackView.addEventListener('singletap', function() {
Ti.API.info('singletap');
ControlView.animate({view:FrontView,transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
});
$.scrollable_view.addView(ControlView);
ControlView.add(BackView);
ControlView.add(FrontView);
rows.next();
} //endwhile
Can anybody help?
If you put a return variable in your event callbacks, you can get access to the source of the tap. Try this and see if it works:
FrontView.addEventListener('singletap', function(e) {
Ti.API.info('singletap');
e.source.animate({view:BackView,transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT});
});
BackView.addEventListener('singletap', function(e) {
Ti.API.info('singletap');
e.source.animate({view:FrontView,transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
});
I found out that it works when you flip the card in the EventListener of your Scrollable View.
Check this out: https://gist.github.com/4683264
I've been searching around on how to do this, but I've been unsuccessful.
What I'm trying to accomplish is this: I have a TableView with, say, 5 rows. I want to be able to swipe a row left to expose information "behind" the row. Not sure if this would be done by adding an additional row to the TableView and placing it behind, or what?
At the end of the day, what would be even cooler, would be to be able to swipe the row left OR right, and depending on which direction you swipe, the row behind gets populated with different information.
Any ideas?
From your description, it sounds like you want something similar to what Twitter does when you swipe across a Tweet.
First, make sure the rows in the table don't have vertical/horizontal layouts.
Then create the left and right swipe views you want for each row, like so:
var leftSwipeView = Ti.UI.createView({
width: Ti.UI.FILL,
height: Ti.UI.FILL,
backgroundColor: '#ff0000', //just to make the effect apparent
visible: false
}
var rightSwipeView = Ti.UI.createView({
width: Ti.UI.FILL,
height: Ti.UI.FILL,
backgroundColor: '#00ff00', //just to make the effect apparent
visible: false,
}
row.add(leftSwipeView);
row.add(rightSwipeView);
row.addEventListener('swipe', function(e) {
if (e.direction == 'left'){
leftSwipeView.setVisible(true);
setTimeout(function(){leftSwipeView.setVisible(false);}, 2000);
}
if (e.direction == 'right'){
rightSwipeView.setVisible(true);
setTimeout(function(){rightSwipeView.setVisible(false);}, 2000);
}
});
The snippet I have up there will hide the views again after 2 seconds. Hope that helps.
Found the perfect solution on Github.
https://github.com/rborn/TiSwipeToReveal