Titanium: Create fields like the ones in iPhone Contacts (Edit Mode) app - iphone

Note: The divider aka separator is the main point of this question. It must be visible.
Is there a way to create fields like the ones in the iPhone Contacts (Edit Contact Mode) app?
I want to create a separator that separates the titleLabel from the textField.
Like " First Name | hinttext "
Instead of " First Name hinttext "
I think what I am trying to do is similar to this... except that I am using Titanium. Is there any way to do this using Titanium?
How is iPhone Contact app's detail View implemented
#MRT and anyone who knows:
How would you make the combined view such that it looks like this?
____________________
( Name | hinttext )
--------------------

You will have to create a new TableViewRow and customize it.
You can put labels, fields, images, etc. in the TableViewRow.
Example:
var row = Ti.UI.createTableViewRow();
var label = Ti.UI.createLabel({
text: "Name",
width: 50,
top: 5,
bottom: 5,
left: 5,
font: {fontSize:10}
});
row.add(label);

Try it this really usefull to you
var view1 = Ti.UI.createView({
height : 50,
width: 150,
top: 5,
bottom: 5,
left: 5,
font: {fontSize:10}
});
var text1 = Ti.UI.createTextField({
hintText : 'First Name',
height : 50,
width: 75,
top: 0,
left: 0,
font: {fontSize:10}
});
var text2 = Ti.UI.createTextField({
hintText : 'hint text',
height : 50,
width: 75,
top: 0,
left: 75,
font: {fontSize:10}
});
view1.add(text1);
view1.add(text2);

you have 2 way to do this.
take 2 TextField and adjust (top and left margin) and joint it.
or
1 Take 1 TextField
2. take 1 Label and its width 2 and height is equal to the textfield height.
3. TextField.add(lable1)
var win1 = Ti.UI.createWindow({
title : 'Window1',
backgroundColor : '#f00',
id : 0,
});
var text1 = Ti.UI.createTextField({
width : 150,
height : 50,
borderRadius : 9,
backgroundColor : '#fff',
top : 50,
left : 20,
});
var label1 = Ti.UI.createLabel({
width : 2,
height : 50,
top : 0,
left : 75,
});
text1.add(label1);
win1.add(text1);
win1.open();

To add a vertical line
var vline = Ti.UI.createView({
height: 44,
width: 1,
top: 0,
left: 85,
backgroundColor:'#CCC'
});
row.add(vline);

You just have to create a TableViewRow and add labels to it. There is not a ready template to this rows. But you can create an wrapper to it, if you will use it a lot. For example:
var createTableViewRowWithTitleAndValue(title, value) {
// TableViewRow
row = Ti.UI.createTableViewRow({
backgroundColor: "#FFFFFF"
});
// Title
row.add(Ti.UI.createLabel({
text: title,
left: 5,
font: { fontWeight: "bold" }
}));
// Value
row.add(Ti.UI.createLabel({
text: value,
right: 5,
textAlign: "right"
}));
}
Then, when you set data to TableView, instead you create a new TableViewRow, you create a new tableViewRowWithTitleAndValue, with title and value needed. For example:
rows.push(new createTableViewRowWithTitleAndValue("Foo", "Bar"));

Related

Is it possible to create a button which when pressed it replaces an existing object on the screen to another object in Smartface App Studio?

Is it possible to create a button which when pressed it replaces an existing object on the screen to another object in Smartface App Studio?
I've tried using the Onshow event on the text however it wasn't successful.
Thankyou
It is possible to replace an existing object to another object. You should create objects and add to page both of them but visible property of an object should be false on start and then you can change visible of object when button is pressed.I create a simple example for you:
var btn = new SMF.UI.TextButton({
top : "80%",
left : "10%",
onPressed : page1_btn_onPressed
});
Pages.Page1.add(btn);
var myImage = new SMF.UI.Image({
top: "20%",
left: "15%",
height: "20%",
width: "70%",
image: "default.png",
imageFillType: SMF.UI.ImageFillType.stretch,
visible : true
});
Pages.Page1.add(myImage);
var myImage2 = new SMF.UI.Image({
top: "20%",
left: "15%",
height: "20%",
width: "70%",
image: "icon.png",
imageFillType: SMF.UI.ImageFillType.stretch,
visible : false
});
Pages.Page1.add(myImage2);
function page1_btn_onPressed(e) {
myImage.visible= false;
myImage2.visible = true;
}

AsyncDisplayKit - ASButton Size

Table Cell
I'm learning to use Asyncdisplaykit. My result is in picture below.
But I don't know how to constraint button equal Screen.width/3, Its auto constraints equal image width.
This is my code
let controlStack = ASStackLayoutSpec(direction: ASStackLayoutDirection.Horizontal, spacing: 3.0, justifyContent: ASStackLayoutJustifyContent.Center, alignItems: ASStackLayoutAlignItems.Center, children: [self.mFavoriteButton, self.mCommentButton, self.mShareButton])
controlStack.spacingAfter = 3.0
controlStack.spacingBefore = 3.0
let insetDateLayout = ASInsetLayoutSpec(insets: UIEdgeInsets(top: 10, left: self.frame.size.width - 100, bottom: 0, right: 0), child: self.mDateTimeNode)
let imageLayout = ASStaticLayoutSpec(children: [imagePlace, insetDateLayout])
return ASStackLayoutSpec(direction: .Vertical, spacing: 3.0, justifyContent: ASStackLayoutJustifyContent.Start, alignItems: ASStackLayoutAlignItems.Center, children:[imageLayout, self.mMessageNode, controlStack])
try change ASStackLayoutAlignItems.Center to ASStackLayoutAlignItems.Stretch. And try enable Grow Constraints for buttons (need to test it):
self.mFavoriteButton.flexGrow = true;
self.mCommentButton.flexGrow = true;
self.mShareButton.flexGrow = true;
Reply if you were able to address the problem!
Typically you want to use flexBasis with a relative size of 0.33 to do 1/3rd. Check out documentation on Web / CSS flexbox for examples of flexbasis.

Why does this window show up as shorter than what was set?

I am creating an app window like this:
var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;
//Create the app window
chrome.app.window.create(
'test.html',
{
frame: "none",
bounds:
{
width: 700,
height: 600,
left: Math.round((screenWidth-width)/2),
top: Math.round((screenHeight-height)/2)
},
maxWidth: 700,
maxHeight: 600,
resizable: false,
id: "test"
}
);
but it shows on screen as only 591 pixels tall!
When I view the HTML/CSS in Chrome as a local HTML page, it shows as the proper height of 600 pixels tall. Why does creating it as a window make it 9 pixels too short?
It was caching the size I had set the window to in a previous version and not allowing that to be changed via the create method. The only fix I found was to do:
function(myWin)
{
myWin.moveTo( Math.round((screenWidth-width)/2), Math.round((screenHeight-height)/2) );
myWin.resizeTo( 700, 600 );
}
in the callback for the create method

Titanium button not changing background color when selected

I have a newbie question: A simple button I've created in Titanium for iPhone refuses to change colors when clicked. Originally I used a button for this function; since it didn't work, I changed to a View, but neither works. Here it how it is set up:
var quifButton = Ti.UI.createView({ // tried this with createButton, as well
top: 44, left: 5, width: 310, height: 42,
backgroundColor: '#333',
backgroundSelectedColor: '#fff',
backgroundFocusedColor: '#fff',
touchEnabled: true,
borderColor: BOR_DK, borderWidth: 2, borderRadius: 5 });
When I click the Button / View in the iPhone simulator, nothing happens. Any ideas why this doesn't work and how I can make it work?
Click is not same than focus. If you want to change color on click, you have to add eventlistener to button or view.
quifButton.addEventListener('click', function(e){
quifButton.backgroundColor = '#fff';
});
*Edit:
backgroundSelectedColor: '#fff',
backgroundFocusedColor: '#fff',
These are not supported in iOS.
This is a limitation in iOS, and is not related to Titanium.
Try this instead for the behaviour you're looking for:
someBtn.addEventListener('touchstart', function() {
someBtn.backgroundColor = 'green';
});
someBtn.addEventListener('touchend', function() {
someBtn.backgroundColor ='blue';
});
your code works perfectly fine with me. can you try and let me know if it works or not?
var win1 = Ti.UI.createWindow({
title:'home',
backgroundColor:'white'
});
var button1 = Ti.UI.createButton({
top: 44,
left: 5,
width: 310,
height: 42,
backgroundColor: '#333',
backgroundSelectedColor: '#fff',
backgroundFocusedColor: '#fff',
touchEnabled: true,
borderWidth: 2,
borderRadius: 5
});
win1.add(button1);
win1.open();
can you use backgroundSelectedColor:"#colorcode" in the tss.hope it ll work
use backgroundSelectedColor:"color" ,it ll work

Overriding the always-top property of the navigation bar in Titanium

In Titanium for iPhone is it possible to display something above the navigation bar – or just disabling the always-top property of the navigation bar?
This is how it looks right now:
This is part of the actual Photoshop-mock-up:
The code-snippet invoking this is:
var win1 = Titanium.UI.createWindow({
title: 'Home',
navBarHidden: false,
barImage: 'topbar.png',
backgroundImage: 'bga.png'
});
c = Titanium.UI.createImageView({
image: 'logobar.png',
top: -13,
right: 7,
width: 74,
height: 108,
exitOnClose: !0
})
try {
win1.add(c);
c.animate({zIndex:3});
win1.addEventListener('focus', function () {
Titanium.App.Analytics.trackPageview('/win1')
});
}catch(e){
alert(e);
}
The try-catch was implemented as I didn't trust the existence of .animate, however it did exist but did not work.
Answer(, or maybe not what it should be like)
Titanium itself does not support the feature of manipulating the zIndex or rather the onTop-properties. However, I've found a workaround allowing the overlay to be shown.
This workaround works by the way Titanium handles windows. First, we define the main window (e.g. win1) and fill it. Then we create an assistant window (e.g. win1a) and assign the ImageView to it. Then we position the new window on top of the other window and voilà.
var win1 = Titanium.UI.createWindow({
title: "*******",
navBarHidden: false,
barImage: 'topbar.png',
backgroundColor: "gray",
});
var win1l = Titanium.UI.createWindow({
title: "",
navBarHidden: true,
height: 84,
width: 64,
right: 0,
top: 0
});
// Inject ImageView into top-most window
win1l.add(Titanium.UI.createImageView({
image: "logobar.png",
top: 2,
right: 5,
width: 60.3, //74, // 74/108 = 0.6851851852
height: 88, //108, // ((108-20)*(74/108)) = 60.29629 ~ 60.3
exitOnClose: !0
}));
win1l.open();
I hope this might have been helpful for you.
Thanks, -Kenan.