How do I draw a line in Titanium? - iphone

How Do I draw a line in Titanium that works in both Android and iPhone?

To create a line, I use;
var view = Ti.UI.createView({
height:180,
width:300
});
var line = Ti.UI.createView({
height:2,
bottom:0,
left:0,
right:0,
borderWidth:1,
borderColor:'#aaa'
});
view.add(line);

Add this to your view.xml
<View class="line"></View>
Add this to your style.tss
".line": {
height: '2dp',
bottom: '2dp',
left: '0dp',
right: '0dp',
borderWidth: '1',
borderColor:'#aaa',
}

you could create webview and use the <canvas> tag to draw in the web view

Related

Dynamically position widget in stack Flutter

I am trying to create a view that consist of a background image with widgets positioned dynamically in certain places on this image, each widget will have an x and y that needs to be calculated for different screens and for different image sizes.
what i did so far was showing the image in a stack and made a list of widgets where each widget type is being checked then create a flutter widget that corresponds with it adding it to this list and displaying it over the image in the stack, but i am looking for a cleaner way to create this behavior, also when rotating the screen the widgets are not being placed in a correct position,
Thank you for your time.
You can do something like:
Stack(
children: [
Image.asset('YOUR IMAGE HERE', fit: BoxFit.cover), // this is your bg image,
..List.generate(imagesCollection.length, (index) {
// you could encapsulate all this logic in a separate widget
var img = imagesCollection[index];
var r = Random();
// make sure to stay within the bounds of your screen
var screenWidth = MediaQuery.of(context).size.width;
var screenHeight = MediaQuery.of(context).size.height;
var randomX = r.nextInt(screenWidth);
var randomY = r.nextInt(screenHeight);
// before you position the image, check that is within the bounds
// check if the randomX - IMAGE_WITH is less than the screen width, same for the height
return Positioned(
top: randomY,
left: randomX,
child: Image.asset(img, width: IMAGE_WIDTH, height: IMAGE_HEIGHT)
);
}
]
)
Something around those lines.

Flutter - Controllable Sprite/Gif Animation on Overlay

I want to show some animation when user tap on the screen. The animation need to be controllable too as it needs to be reset after each tap.
What I have tried:
1. Show a Gif image in Overlay.
RenderBox renderBox = context.findRenderObject();
var size = renderBox.size;
var offset = renderBox.localToGlobal(Offset.zero);
_myGif = Image.asset('images/mygif.gif', width: 100, height: 100,);
return OverlayEntry(
builder: (context) => Positioned(
left: offset.dx - 50.0 + size.width/2,
top: offset.dy - 50.0 + size.height/2,
child: Container(
child: _myGif
),
)
);
Problem: The Gif animation is not controllable. The animation also appears to be played from random frames and end at random frames each time.
Use third party widget (gif_ani)
_animationCtrl = GifController(vsync: this, duration: new Duration(milliseconds: 1000), frameCount: 38);
_mygifAnimation = GifAnimation(
width: 100.0,
height: 100.0,
image: AssetImage('images/mygif.gif'),
controller: _animationCtrl,
);
Problem: It only works when it's not on an Overlay. When the GifAnimation is added as a child in Overlay it doesn't display at all.
Use Flame to run sprite sheet
Problem: AnimationAsWidget doesn't fit my requirement as I need to control the animation. Other ways would make my code too complex as I'm not building a game.
Is there any solution on this? Thank you in advance.

How to adjust vertically single line string in NSTextField?

I am using custom font for non-editable NSTextField, which I created in StoryBoard:
generalDisplay.font = NSFont(name: "DS-Digital Bold", size: 25.0)
Then I am adjusting frame height:
generalDisplay.frame.size.height = 28
The result is not centered vertically:
I've tried to turn off single line mode, but the result is even worse.
If I should subclass it, could you give me an example what methods I have to override?
You can subclass UITextField and override this method:
override func textRect(forBounds bounds: CGRect) -> CGRect {
return bounds.inset(by: UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 10))
}
Looking at the Apple documentation for NSTextfield maybe you could initialize your NSTextField with a NSAttributedString to be able to change the baseline
NSTextfield(labelWithAttributedString: NSAttributedString)

How to create a table with fixed length inside a scrollView in Appcelerator Titanium?

I'm trying to add some imageViews and a tableView into scrollView in Titanium. I want the scrollView to be scrollable but not the tableView inside, so I set tableView.scrollable to false. However, even if the height of the scrollView exceeds the height of the screen, it is not scrollable. Since it's not encouraged to put a tableView inside a scrollView, I'm wondering if there is a better way to create a table with fixed length inside a scrollView in Titanium?
The following is my code:
var view = Ti.UI.createScrollView({
contentWidth:'auto',
contentHeight:'auto',
top:0,
showVerticalScrollIndicator:true,
showHorizontalScrollIndicator:true,
});
var imageview1 = Ti.UI.createImageView({
image: "../images/headers/gscs_logo.png",
height: 80,
left: 10,
right: 10,
top: 10,
});
var imageview2 = Ti.UI.createImageView({
image: "../images/headers/wellness_logo.png",
height: 80,
left: 10,
right: 10,
top: 90,
});
view.add(imageview1);
view.add(imageview2);
var tableview = Ti.UI.createTableView({
data: [{title:'a'}, {title:'b'}, {title:'c'}, {title:'d'}, {title:'e'}, {title:'f'}, {title:'g'}],
top: 180,
scrollable: false,
});
view.add(tableview);
Ti.UI.currentWindow.add(view);
This is the window I got (StackOverflow does not allow new users to post images, sorry).
This is the window I want. The table has fixed number of rows and its parent view can be scrolled.
I have also tried to set currentWindow.layout to "vertical", but that failed since neither the scrollView nor the tableView would show up.
Thank you for your patience and help!
After looking at Kitchen Sink, Titanium's demo app, I figured out how to do this: just set tableview.style to Titanium.UI.iPhone.TableViewStyle.GROUPED, and and set the imageView as tableview.headerView.
var imageview = Ti.UI.createImageView({
image: "../images/headers/bakerinstitute_logo.png",
height: 100,
left: 40,
right: 40,
top: 10,
});
var tableview = Ti.UI.createTableView({
data: [{title:'a', header:'first one'}, {title:'b'}, {title:'c'}, {title:'d'}, {title:'e'}, {title:'f'}, {title:'g'}, {title:'h'}, {title:'i'}, {title:'j'}, {title:'k', header:'last one'}],
style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
backgroundColor:'transparent',
rowBackgroundColor:'white',
headerView: imageview
});
Ti.UI.currentWindow.add(tableview);
You should check out the UICatalog sample code provided by apple. There are many views, and some of them look like the one you provided a link for. Hope that Helps!

BackgroundImage problem with my back button

I have a concern that the image I attributed back button does not appear I added this statement but it does nothing
win1.setBackButtonTitleImage('back.png');
here is the code
var ButtonRetour = Ti.UI.createButtonBar({labels:['Retour'],
backgroundColor:'#ae4041',
backgroundImage:'back.png',
color:'#ffffff' });
ButtonRetour.addEventListener('click',
function(){ tabGroup.close(); });
win1.leftNavButton = ButtonRetour;
win1.setBackButtonTitleImage('back.png');
you have an idea about the problem
thank you
I found the solution
I actually changed the code for the creation of back button using the following
var backButton = Ti.UI.createButton({
title:'Accueil',
backgroundImage:'images/back.png',
font:{fontSize:13,fontWeight:'bold'},
textAlign:'center',
width:75,
height: 35
});
backButton.addEventListener('click', function(){
tabGroup.close();
});
win1.leftNavButton = backButton;
Try that. Note, that I am not sure whether you can use both backgroundColor and backgroundImage:
var ButtonRetour = Titanium.UI.createButton({
title:'Retour',
backgroundColor: '#ae4041', // i am not sure whether you can use both bgColor and bgImage
backgroundImage:'back.png',
width:100, //set proper width here
height:20 //set proper height here
});
ButtonRetour.addEventListener('click', function() {
tabGroup.close();
});
win1.leftNavButton = ButtonRetour;